Quinn-Curtis Forums
Quinn-Curtis Forums
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Tools for Microsoft .Net & .Net Compact Framework
 QCChart2D and QCChart2D CF (VB and C#)
 Different colors for Pos/Neg bars?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Mark

2 Posts

Posted - 08 Apr 2005 :  13:56:35  Show Profile  Reply with Quote
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  Show Profile  Reply with Quote
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);
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
Quinn-Curtis Forums © 2000-07 Quinn-Curtis, Inc. Go To Top Of Page
Powered By: Snitz Forums 2000 Version 3.4.07