我試圖在我的web應用程序上部署一些圖表,但遇到StackedColumn圖表出現問題;該系列文章要麼彼此重疊,要麼相互分離,結果是整體總數被歪曲。這裏有兩個例子,說明每一個問題:ASP.net StackedColumn圖表系列 - 重疊和間隙
http://sdrv.ms/17nzZ2k - 系列之間的差距
http://sdrv.ms/1fg6LqW - 重疊系列
這是我的代碼生成圖表:
Private Sub chartMonMStack_DataBinding(sender As Object, e As System.EventArgs) Handles chartMonMStack.DataBinding
Dim chart As Chart = chartMonMStack
Dim cArea As String = "area"
chart.ChartAreas(cArea).Position.Width = 85
chart.ChartAreas(cArea).Position.Height = 100
chart.ChartAreas(cArea).AxisX.MajorGrid.LineColor = Drawing.ColorTranslator.FromHtml("#999999")
chart.ChartAreas(cArea).AxisY.MajorGrid.LineColor = Drawing.ColorTranslator.FromHtml("#999999")
chart.ChartAreas(cArea).AxisX.Title = "年"
chart.ChartAreas(cArea).AxisY.Title = "NTD"
chart.ChartAreas(cArea).AxisY.LabelStyle.Format = "#,##0"
Dim conStr As String = ConfigurationManager.ConnectionStrings("GenshenPOS").ConnectionString
Dim conn As New SqlConnection(conStr)
conn.Open()
Dim sql As String = "SELECT [y], [Store], SUM([amount]) AS [NTD] FROM vwMonthly " & _
"WHERE [m] = '" & dropMonth.SelectedValue & "月' GROUP BY [y], [Store] ORDER BY [y], [Store]"
Dim sqlPoints As New SqlCommand(sql, conn)
Dim reader As SqlDataReader = sqlPoints.ExecuteReader()
While reader.Read()
If chart.Series.IndexOf(reader.Item("Store")) = -1 Then
chart.Series.Add(reader.Item("Store"))
chart.Legends.Add(reader.Item("Store"))
chart.Series(reader.Item("Store")).ChartType = SeriesChartType.StackedColumn
chart.Series(reader.Item("Store")).ChartArea = cArea
chart.Series(reader.Item("Store")).IsValueShownAsLabel = True
chart.Series(reader.Item("Store")).LabelFormat = "#,##0"
chart.Series(reader.Item("Store")).LabelForeColor = Drawing.Color.White
End If
chart.Series(reader.Item("Store")).Points.AddXY(reader.Item("y"), reader.Item("NTD"))
End While
conn.Close()
End Sub
我讀過,如果系列具有空白數據點,則由於缺少數據可能會出現間隙,但是在受影響的列上,沒有缺失數據點。此外,我不認爲這可以解釋爲什麼在其他情況下,酒吧重疊,並沒有正確定位自己的圖表。儘管如此,我嘗試添加以下內容但無濟於事。
For Each s As Series In chart.Series
chart.DataManipulator.InsertEmptyPoints(1, IntervalType.Number, s)
Next
如果有人能幫助,我會很感激!