I'm trying to get access to The Graph (bar graph) data points in order to change their background colors.
Anyone knows how to get to these data points?
5 Answers, 1 is accepted
Graph series have a ColorPalette property that you can modify according to your requirements.
You can refer to Formatting a Graph(Formatting Series colors) help article that describes how to add custom colors to series ColorPalette.
Regards,
Katia
Telerik
Thank you for your Reply Katia;
I've attached 3 images describing the problem I'm having with my Chart.
My data has 2 columns: 'Year' and 'Amount'
I need a column chart that shows each 'Year' in a Column with a different color.
The nicest looking chart I got was when I assign the Chart categories to 'Year' and Chart values to 'Amount', but this makes all the columns of the same color (see attached image g1.png).
When I assigned the Chart series to 'Year' and Chart values to 'Amount', I got all the columns to be attached to each other, and the x-axis title to be 'All' instead of each column having it's own title (see attached image g2.png).
Last, I've assigned the Chart categories and Chart series to be 'Year' and the Chart value to be 'Amount'.
the result was a thin, left aligned columns (see attached image g3.png).
I'm best looking one is my first attempt, so I thought I can solve the column colors issue by accessing the graph data points and override the assigned colors
As your data is not grouped by the series, ColorPalette property will not be in use as it assigns colors to different series but not to different data point values.
In order to set a custom color per column, you need to set conditional formatting rules for barSeries (see the attached report). However, when the values for data points are unknown you might need to create the Graph item programmatically and add your custom logic for setting the colors.
Regards,
Katia
Telerik
Hello Katia;
I've been working on this for quite some time with no luck.
can you please send me or point me to a sample that clearly shows how to create Graph item programmatically and set the background color to them ?
thank you.
You can find attached a simplified example demonstrating how to set BackgroundColor for DataPoints programmatically. This approach can be applied to your scenario after considering your real data and other specifics.
In general, when you want to control the report programmatically you can first test the approach in the Designer and then review the code automatically generated in .Designer.cs file. This will give you an idea how the items are generated in code behind. You can modify the sample code according to your requirements and place after InitializeComponent() method.
Regards,
Katia
Telerik