|
Dim sql As String, i
Dim yf(2) As Object, sal(1, 11) As Object, yy(2) As Object
'With yf
yf(0) = "Company"
yf(1) = "实用水量"
yf(2) = "应缴水量"
''End With
''sal(0) = yf
Dim y, s, yj
For i = 0 To 11
Conn.Open()
sql = "SELECT SUM(应缴度数) AS 应缴水量, SUM(实用度数) AS 实用水量, 年份, 月份 FROM 用水量 WHERE (年份 = 2016) AND (月份 = " & i + 1 & ") GROUP BY 年份, 月份"
Dim sqlcmd As New SqlCommand(sql, Conn)
Dim rs As SqlDataReader = sqlcmd.ExecuteReader()
If rs.HasRows = True Then
rs.Read()
y = rs("月份")
s = rs("实用水量")
yj = rs("应缴水量")
Else
y = i + 1
s = 0
yj = 0
End If
'MsgBox(y & "/" & s & "/" & yj)
yy(0) = y & "月"
yy(1) = s
yy(2) = yj
Conn.Close()
sal(0, i) = yy
Next
Dim Sales(,) As Object = New Object(,) {{yf}, {sal(0, 11)}}
' Dim Sales(,) As Object = New Object(,) _
'{{"Company", "Company A", "Company B"}, _
'{"June", 20, 10}, _
'{"July", 10, 5}, _
'{"August", 30, 15}, _
'{"September", 14, 7}}
chtSales.ChartData = Sales
'Add a title and legend.
With Me.chtSales
.Title.Text = "test"
.Legend.Location.LocationType = _
MSChart20Lib.VtChLocationType.VtChLocationTypeBottom
.Legend.Location.Visible = True
End With
'Add titles to the axes.
With Me.chtSales.Plot
.Axis(MSChart20Lib.VtChAxisId.VtChAxisIdX).AxisTitle.Text = "Year"
.Axis(MSChart20Lib.VtChAxisId.VtChAxisIdY).AxisTitle.Text = "Millions of $"
End With
Dim r, g, b
'Set custom colors for the bars.
With Me.chtSales.Plot
'Yellow for Company A
' -1 selects all the datapoints.
For i = 1 To 1
r = CInt(Int((250 * Rnd()) + 0))
g = CInt(Int((250 * Rnd()) + 0))
b = CInt(Int((250 * Rnd()) + 0))
'Console.WriteLine(r & "/" & g & "/" & b)
.SeriesCollection(i).DataPoints(-1).Brush.FillColor.Set(r, g, b)
'Purple for Company B
'.SeriesCollection(2).DataPoints(-1).Brush.FillColor.Set(200, 50, 200)
Next
End With
各位大哥大姐~如何让数组可以像下面的一样?我该怎么做?
Dim Sales(,) As Object = New Object(,) _
{{"Company", "Company A", "Company B"}, _
{"June", 20, 10}, _
{"July", 10, 5}, _
{"August", 30, 15}, _
{"September", 14, 7}}
==============================================
这样的读数据库建数组,我是建错了~希望各位大哥大姐帮帮我,我应该怎么做?
Dim sql As String, i
Dim yf(2) As Object, sal(1, 11) As Object, yy(2) As Object
'With yf
yf(0) = "Company"
yf(1) = "实用水量"
yf(2) = "应缴水量"
''End With
''sal(0) = yf
Dim y, s, yj
For i = 0 To 11
Conn.Open()
sql = "SELECT SUM(应缴度数) AS 应缴水量, SUM(实用度数) AS 实用水量, 年份, 月份 FROM 用水量 WHERE (年份 = 2016) AND (月份 = " & i + 1 & ") GROUP BY 年份, 月份"
Dim sqlcmd As New SqlCommand(sql, Conn)
Dim rs As SqlDataReader = sqlcmd.ExecuteReader()
If rs.HasRows = True Then
rs.Read()
y = rs("月份")
s = rs("实用水量")
yj = rs("应缴水量")
Else
y = i + 1
s = 0
yj = 0
End If
'MsgBox(y & "/" & s & "/" & yj)
yy(0) = y & "月"
yy(1) = s
yy(2) = yj
Conn.Close()
sal(0, i) = yy
Next |
|