This is a migrated thread and some comments may be shown as answers.

Telerik Reporting Bar Chart colors

5 Answers 133 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Shea
Top achievements
Rank 1
Shea asked on 15 Nov 2012, 08:51 PM
I am trying to create a bar chart in a Telerik Report. I have a SQL stored procedure that gathers the data and returns the number of items that are different colors. My items can be one of six color (Green, Gray, Orange, Yellow, Black, or Red). I then need the bar chart to display the x-axis label with the color name and the to color that bar with the color represented. I have tried two different stored procedures that return the data in two different formats. One method returns two columns one for the name of the color and the second for the count of items with that count. There a total of six rows returned, one row per color. The second method returns just one row and six columns, each column name is the colorname and has the count. Method one lets me set the X-Axis labels to the color name and shows the proper count but I cannot find a way to change the color of each bar on the chart. I can only set one color for all bars. If I try the second method of data, I can set up a custom palette and create a series with enough items to patch but I cannot put the color names under each bar on the chart. Any assistance or suggestions would be greatly appreciated.

5 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 16 Nov 2012, 12:11 PM
Hello Shea,

By default the chart is designed so that all bars from a series have the same colors. If you need each to have a different color, you need to loop through each chart series item and assign the respective color e.g.:

int i = 0;
foreach (ChartSeriesItem item in chart1.Series[0].Items)
{
       item.Appearance.FillStyle.MainColor = barColors[i++];
}

Regards,
Steve
the Telerik team

HAPPY WITH TELERIK REPORTING? Do you feel that it is fantastic? Or easy to use? Or better than Crystal Reports? Tell the world, and help fellow developers! Write a short review about Telerik Reporting and Telerik Report Designer in Visual Studio Gallery today!

0
Shea
Top achievements
Rank 1
answered on 16 Nov 2012, 03:54 PM
I have found the previous forum posts that show this loop but everytime that I insert that code into the ItemDataBound action or the NeedDataSource, the code is ignored and the bars show up with the default color.
0
Steve
Telerik team
answered on 16 Nov 2012, 04:29 PM
Hi Shea,

The approach suggested in previous post won't work if you have bound the chart declaratively i.e. set the DataSource property to an SqlDataSource component or have set DataSource in NeedDataSource event of the chart. Both these approaches lead to automatically generated series and series items that we have no control over. You would need to build the chart entirely programmatically and this way you would have full control over its styling. For more info, check How-To: Programmatically Data Binding Chart to a Generic List of Objects help article.

Regards,
Steve
the Telerik team

HAPPY WITH TELERIK REPORTING? Do you feel that it is fantastic? Or easy to use? Or better than Crystal Reports? Tell the world, and help fellow developers! Write a short review about Telerik Reporting and Telerik Report Designer in Visual Studio Gallery today!

0
Shea
Top achievements
Rank 1
answered on 16 Nov 2012, 07:26 PM
Thanks for the link. How would I modify this example to pull data from SQL stored procedure since this example uses a fixed data that is set at design time? I need my data to be pulled each time the report is run.
0
Steve
Telerik team
answered on 20 Nov 2012, 04:45 PM
Hello Shea,

You can use ADO.NET and the SqlDataAdapter class to connect to your sql server and get the data you would use for building the chart.

Regards,
Steve
the Telerik team

HAPPY WITH TELERIK REPORTING? Do you feel that it is fantastic? Or easy to use? Or better than Crystal Reports? Tell the world, and help fellow developers! Write a short review about Telerik Reporting and Telerik Report Designer in Visual Studio Gallery today!

Tags
General Discussions
Asked by
Shea
Top achievements
Rank 1
Answers by
Steve
Telerik team
Shea
Top achievements
Rank 1
Share this question
or