I have a bar series that has positive and negative values. I want the positive values to appear in Green bars and the negative values to appear in Red bars. I can set all bar colors using the Brush property, but is there a way to set the color based on the value (perhaps with a converter)?
Thanks
Russell
Hello,I need sample in Visual basic dealing with "BarSeries Bar Color Based On Value"Can you help me, please.
Save yourself all this.
Simply add a marker template to your serie, something as simple as "new DataTemplate() { VisualTree = new FrameworkElementFactory(typeof(Ellipse)) };"
Then, add an event handler on your chart's RefreshCompleted.
In this handler, do something like this :
Canvas canvas = series.FindFirstChild<Canvas>();
List<Rectangle> bars = canvas.FindChildren<Rectangle>().ToList();
List<Ellipse> ellipses = canvas.FindChildren<Ellipse>().ToList();
for (int i = 0; i < bars.Count; i++) { Rectangle r = bars[i]; Ellipse ellipse = ellipses[i]; YourDataElementType element = ((Infragistics.Controls.Charts.DataContext)ellipse.DataContext).Item as YourDataElementType;
Brush brush = GetYourColorFromYourElement(element); if (brush != null) r.Fill = brush; }
Hello Russell,
This is just a follow up if you require any further assistance.
For applying green bars for positive values and red for negative I have attached a sample.