Reputation: 75
I created an asp.net StackedBar chart with values coming runtime from the database.
Here is how it looks :
Why do my colors not change according to the values on the chart ?
So value 56 should show more red color whereas values 1 should show less red color ? Right now, allthough the values are all different, the width of the colors are all same which does not give the right effect of the graph ?
Code used :
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)
Data :
Any help would be appreciated.
Thank you, Dee
Upvotes: 2
Views: 150
Reputation: 13188
Change this:
chart.DataBindCrossTable(DtRecords.DefaultView, "Outcomescore", "ShortName", "Outcomescore", "Label=RecordsPerGroup");
with this:
chart.DataBindCrossTable(DtRecords.DefaultView, "OutcomeScore", "ShortName", "RecordsPerGroup", "Label=RecordsPerGroup");
Upvotes: 1