ChartSeries barSeries = this.chart.Series; barSeries.Chart.Name = "my chart"; barSeries.ItemsSource = valueEnum;I want to color each bar based on the value of the item but not sure how to access the individual bars.
8 Answers, 1 is accepted
Thanks for writing.
You can specify the fill for each bar using the PointTemplates property of your bar series. You can add a DataTemplate to this collection and bind the fill of the bar to some color that changes dynamically based on what the bar represents.
I find a Silverlight sample i have adapted to Windows phone. it works with a viewmodel. If it can help you.
MainPage.xaml (nothing in MainPage.xaml.cs)
Hope it helps
Thank you for contacting us.
You can use the PointTemplateSelector property of the series to set a different template to the data points depending on your custom logic. First, you have to create a class that inherits from the DataTemplateSelector class and override its SelectTemplate method. Then set the PointTemplateSelector to an instance of this class. I have prepared a sample project that demonstrates how you can change the template for the last point.
I hope this was useful. Please, do not hesitate to contact us if you have further questions.Regards,
The example you have attached work. However I have a problem trying to implement it in the case where my horizontal axis is a DateTimeContinousAxis. In this case I can only produce a graph when the series line type is "LineSeries", "ScatterLineSeries" does not work, and the "LineSeries" does not accept XValueBinding and YValueBinding.
Can you please suggest an alternative way to handle the case where the horizontal axis os of DateTimeContinousAxis?
**** Update: I managed to find a working solution, although the "LineSeries" does not support XValueBinding and YValueBinding in XAML code like the "ScatterLineSeries", you can assign these properties in code, so it now works OK.
Thank you for the question.
The difference between Categorical and Scatter series is that while the Categorical Series needs one categorical axis and one numerical axis, the Scatter Series needs two numerical axes. That's why the Scatter Series introduces XValueBinding and YValueBinding properties.
Both the DateTimeCategoricalAxis and the DateTimeContinuousAxis are categorical axes, so they are incompatible with the Scatter Series.
I have modified the project from my previous answer to work with DateTimeContinuousAxis.
I hope this was useful. Please, let us know if you have further questions.
I am not sure if you can not find an attachment at all, or just the project in my post is not the right one. The attachment is just above the Reply button. I have downloaded and opened it and it is exactly the project I have referred to in my post. Just in case, I have attached the project again.
Please, let us know if you still have problems.