我有一个图表控件,我试图用来自 sqldatasource 的多个系列动态填充,这是我的图表控件:
<asp:Chart ID="chartMonthly" runat="server" Width="920px" ImageLocation="~/Images/Temp/ChartPic_#SEQ(300,3)" Palette="Berry">
<ChartAreas>
<asp:ChartArea Name="line"></asp:ChartArea>
</ChartAreas>
</asp:Chart>
以下是我如何动态添加系列和点:
Private Sub chartMonthly_DataBinding(sender As Object, e As System.EventArgs) Handles chartMonthly.DataBinding
Dim conStr As String = ConfigurationManager.ConnectionStrings("GenshenPOS").ConnectionString
Dim conn As New SqlConnection(conStr)
conn.Open()
Dim sqlPoints As New SqlCommand("SELECT [m] AS [月], [Store] AS [門市], SUM([amount]) AS [NTD] FROM vwMonthly WHERE [y] = " & dropYear.SelectedValue & " GROUP BY [m], [Store]", conn)
Dim reader As SqlDataReader = sqlPoints.ExecuteReader()
While reader.Read()
If chartMonthly.Series.IndexOf(reader.Item("門市")) = -1 Then
chartMonthly.Series.Add(reader.Item("門市"))
chartMonthly.Legends.Add(reader.Item("門市"))
chartMonthly.Series(reader.Item("門市")).ChartType = SeriesChartType.Line
chartMonthly.Series(reader.Item("門市")).ChartArea = "line"
End If
chartMonthly.Series(reader.Item("門市")).Points.AddXY("月", "NTD")
End While
conn.Close()
End Sub
该图表正在正确读取商店的名称并根据它们创建系列,但我的图表没有数据 - 没有一个轴有值,并且系列的线条作为 0/Null 值穿过图表底部。
我已经单独运行了基础查询并且数据在那里,我假设它看到了数据,否则将不会创建系列和图例,所以我假设我在向系列中添加点的方式中遗漏了一些东西?!