Author |
Topic  |
|
Mark
2 Posts |
Posted - 08 Apr 2005 : 13:56:35
|
I want to draw a simple bar chart, but I would like to draw negative values in a different color than the positive values. Is this possible without having to create a separate chart element for the negative bars? |
|
quinncurtis
1164 Posts |
Posted - 08 Apr 2005 : 14:32:01
|
You can use what we refer to as segment attributes to assign a unique color to each bar of a simple bar plot. Below is a simple modification to our SimpleBarChart.cs example from the ChartTabDemo example program, that uses a threshold of 200 instead of your 0. You just run through each bar, look at the assoicated value and assign the appropriate color.
ChartAttribute attrib1 = new ChartAttribute (Color.Green, 0,DashStyle.Solid, Color.Green); attrib1.SetFillFlag(true); SimpleBarPlot thePlot1 = new SimpleBarPlot(pTransform1, Dataset1, ChartCalendar.GetCalendarWidthValue(ChartObj.MONTH,8), 0.0, attrib1, ChartObj.JUSTIFY_CENTER); . . .
// START OF ADDED CODE ChartAttribute positiveattrib = new ChartAttribute (Color.Blue, 0,DashStyle.Solid, Color.Blue); ChartAttribute negativeeattrib = new ChartAttribute (Color.Red, 0,DashStyle.Solid, Color.Red); double thresholdvalue = 200; thePlot1.SetSegmentAttributesMode(true); for (i=0; i < Dataset1.NumberDatapoints; i++) { if (Dataset1.YData[i] >= thresholdvalue) thePlot1.SetSegmentAttributes(i,positiveattrib); else thePlot1.SetSegmentAttributes(i,negativeeattrib); } // END OF ADDED CODE
chartVu.AddChartObject(thePlot1);
|
 |
|
|
Topic  |
|
|
|