ASP.NET StackedBar图表意外结果

时间:2017-04-03 15:15:28

标签: asp.net .net vb.net charts mschart

我创建了一个asp.net StackedBar图表,其中包含来自数据库的运行时值。

以下是它的外观:

enter image description here

为什么我的颜色不会根据图表上的值而改变?

因此值56应显示更多红色,而值1应显示更少的红色?现在,尽管这些值都是不同的,但颜色的宽度都是相同的,不能给出图形的正确效果?

使用的代码:

Dim chart As New Chart
                chart.ID = DtDistinct.Rows(I)("CourseSisID")

                Dim chartareas As New ChartArea
                chart.ChartAreas.Add(chartareas)

                ' chart.DataBindTable(DtRecords.DefaultView)

                chart.DataBindCrossTable(DtRecords.DefaultView, "Outcomescore", "ShortName", "Outcomescore", "Label=RecordsPerGroup")
                chart.ChartAreas(0).AxisY.Interval = 1
                chart.ChartAreas(0).AxisY.LabelStyle.IsEndLabelVisible = True
                chart.Palette = ChartColorPalette.None
                chart.PaletteCustomColors = New Color() {ColorTranslator.FromHtml("#DF5B59"), ColorTranslator.FromHtml("#E0D773 "), ColorTranslator.FromHtml("#8AAC53"), ColorTranslator.FromHtml("#6A843F")}

                chart.ChartAreas(0).AxisX.MajorGrid.Enabled = False
                chart.ChartAreas(0).AxisY.MajorGrid.Enabled = False

                Dim charttitle As New Title
                charttitle.Text = DtDistinct.Rows(I)("CourseSisID")
                chart.Titles.Add(charttitle)

                For Each cs As Series In chart.Series
                    cs.ChartType = SeriesChartType.StackedBar
                Next
                pnlcharts.Controls.Add(chart)

数据:

enter image description here

任何帮助都将不胜感激。

谢谢你, DEE

1 个答案:

答案 0 :(得分:1)

改变这个:

chart.DataBindCrossTable(DtRecords.DefaultView, "Outcomescore", "ShortName", "Outcomescore", "Label=RecordsPerGroup");

用这个:

chart.DataBindCrossTable(DtRecords.DefaultView, "OutcomeScore", "ShortName", "RecordsPerGroup", "Label=RecordsPerGroup");

enter image description here