下午好。我試圖研究,但還沒有找到任何有這方面例子的人,我通常不會尋求幫助,我只是想出了辦法,但是這個人正在殺死我!我試圖動態創建一個堆積面積圖,我已經可以創建一個動態面積圖,但不能爲我的生活弄清楚如何獲得堆積面積圖來堆疊這個系列。我在excel中做了類似的事情,並且我可以很好地表示它,但它不是動態的。 我有一個是奠定了這樣的數據: How the data is laid out試圖創建一個動態的Dundas Stackedarea圖表
這是我多麼希望圖表看: How I want the chart to look
我怎樣才能將數據關聯到類別或不管它是什麼,我需要做的?我有一個數組中的數據,但我似乎無法弄清楚如何讓圖表堆疊。誰能幫忙?如果你需要一些更多的信息,請問,我知道我不包括我的代碼,主要是因爲它很醜陋,而且可以嘗試壓縮一下,並簡化任何需要的代碼。
我的代碼如下(也許這會有所幫助,哪怕是醜陋的)
For tmpatozgroup = 1 To 1
Dim chart1 As New Chart()
chart1.ID = "chrt-" & tmpatozgroup & "-" & atozser
Dim seriesperrow As Integer
Dim chartArea1 As New ChartArea()
chart1.Height = 340
chart1.Palette = ChartColorPalette.Dundas
chart1.BackColor = System.Drawing.Color.LightGray
chart1.BorderSkin.SkinStyle = BorderSkinStyle.Emboss
chart1.BorderLineColor = System.Drawing.Color.Gray
chart1.BorderLineStyle = ChartDashStyle.Solid
chart1.BorderLineWidth = 4
' Set the ChartArea properties
chartArea1.Name = "Default"
chartArea1.BackColor = System.Drawing.Color.LightGray
chartArea1.AxisX.LabelsAutoFit = False
chartArea1.AxisX.LabelStyle.FontAngle = -45
chartArea1.Area3DStyle.Enable3D = True
chart1.ChartAreas.Add(chartArea1)
Dim series1 As New Series()
series1.Name = tblGrouping1(tmpatozgroup, 0)
chart1.Series.Add(series1)
chart1.Legends.Clear()
If Not IsNothing(tblGrouping1(tmpatozgroup, 0)) Then
For tmpatozgroup2 = 1 To 9
Dim legend1 As New Legend()
Dim sername As String
Dim servalues() As Double
Dim serformat As String
Dim chrtSeriesCnt As Integer
sername = tblGrouping1(0, tmpatozgroup2)
'need to tear the current row out of the array and place in tmpseries
Dim tmpatozcnt As Integer
For tmpatozcnt = 1 To 999
If IsNothing(tblGrouping1(0, tmpatozcnt)) Then atozseries = tmpatozcnt : Exit For
tmpSeries(tmpatozcnt) = tblGrouping1(tmpatozgroup2, tmpatozcnt)
chrtSeriesLabels(tmpatozcnt) = tblGrouping1(0, tmpatozcnt)
Next
servalues = tmpSeries
serformat = chrtSeriesForm1
chart1.Width = 1000
seriesperrow = 1
'chart1.AlignDataPointsByAxisLabel()
series1.Type = SeriesChartType.StackedColumn
series1("StackedGroupName") = "'" & tblGrouping1(tmpatozgroup, 0) & "'"
If Not IsNothing(tblGrouping1(tmpatozgroup, 0)) Then
For Each ser As Series In chart1.Series
For i2 As Integer = 1 To atozseries - 1
ser.Points.AddXY(chrtSeriesLabels(i2), servalues(i2 - 1))
ser.Points(i2 - 1).BorderColor = Drawing.Color.FromArgb(Split(sercolor(i2), "|")(0), Split(sercolor(i2), "|")(1), Split(sercolor(i2), "|")(2))
ser.Points(i2 - 1).Color = Drawing.Color.FromArgb(Split(sercolor(i2), "|")(0), Split(sercolor(i2), "|")(1), Split(sercolor(i2), "|")(2))
'ser.XAxisType = AxisType.Secondary
Dim tooltipformat As String
If serformat = "Currency" Then serformat = "$#,##0.00" : tooltipformat = "{$#,#.00}"
If serformat = "###,###,##0.00" Then serformat = "#,##0.00" : tooltipformat = "{#,#}"
If serformat = "###,###,##0" Then serformat = "0" : tooltipformat = "{#,#}"
ser.Points(i2 - 1).ToolTip = ser.Points(i2 - 1).AxisLabel & " : #VALY" & tooltipformat
Next
chart1.ChartAreas(0).AxisX.Interval = 1
chart1.ChartAreas(0).AxisX.LabelStyle.Interval = 1
chart1.ChartAreas(0).AxisX.Title = "test" 'chrtXAxisName
chart1.ChartAreas(0).AxisY.Title = sername
chart1.ChartAreas(0).AxisY.LabelStyle.Format = serformat
chart1.Palette = ChartColorPalette.Dundas
Next
End If
Next
If seriesonrow = seriesperrow Or seriesonrow = 0 Then
tr = New TableRow
tr.CssClass = "charts column"
tr.Style("display") = "none"
End If
td = New TableCell
td.HorizontalAlign = HorizontalAlign.Center
td.ColumnSpan = 6/seriesperrow
td.Controls.Add(chart1)
tr.Cells.Add(td)
tblReport.Rows.Add(tr)
chart1 = Nothing
End If
Next
感謝一大堆提前! 後來
這是用於WinForms的嗎?的WebForms? WPF? – jsanalytics
對不起,它在aspx,VB.net目前,dundas.charting.webcontrol是命名空間,我猜測webforms。 –
我正在建議'System.Web.UI.DataVisualization.Charting',它有一個'StackedArea'圖表類型,但聽起來你已經在使用別的東西了。 – jsanalytics