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

Bar chart reporting dilemma, conditional coloring

2 Answers 150 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 1
Scott asked on 16 Apr 2009, 03:33 PM
I have a bar chart in a report, and I'm trying to color some of the bars (red) if they are below a certain value.  The two options I am aware of for this are:

1) When NeedsDataSource is fired, populate my own ChartSeries as I iterate through a SqlDataReader.  This allows me to set the FillStyle.MainColor for each ChartSeriesItem I add, and I can set it to Red if I want.  HOWEVER, the short-coming here is that I see no way to control the XAxis labels for each data point, and I want them to display the associated date with each data point (they end up just being 1, 2, 3, 4, etc.).

2) In the NeedsDataSource event, set the DataSource to a DataView.  This also allows me to set the XAxis.DataLabelsColumn property so that I can appropriately label my XAxis.  HOWEVER, if I try to change the color of the bar in the ItemDataBound event by iterating through the series items and setting the color, it doesn't work.  The color never changes.  The color appears to be set the moment it is added to the chart, and is unalterable after that point.

Any solution to this dilemma?

Regards,
Scott

UPDATE: Okay, I have a solution.  It certainly doesn't seem elegant, but it works, but I would still like to know if there is a more direct route.  Seems like #2 above would be easiest, and just access the chart items once they've been added to change their color, but that doesn't seem to work.

The solution I came up with after reading this: http://blogs.telerik.com/blogs/08-06-20/formatting_radchart_labels.aspx

I set the XAxis.AutoScale to false, then manually add each of my ChartAxisItems and set the TextBlock.Text property to the text I want.  This certainly doesn't seem intuitive.

Is there a better way?

2 Answers, 1 is accepted

Sort by
0
Accepted
Steve
Telerik team
answered on 21 Apr 2009, 04:03 PM
Hi Scott,

The solution you've found is correct and is one way to handle such scenario and it is given as example of adding axis labels programmatically here. The chart item has no intrinsic support for DateTime values. To show DateTime values the chart expects a data source of doubles which are internally converted to DateTime using DateTime.ToOADate() method, which is the second available approach (more info here).
As for changing the colors of the separate bars, please use the NeedDataSource event instead and make sure there is no SeriesPallete set (which would override whatever you're setting).

Kind regards,
Steve
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Scott
Top achievements
Rank 1
answered on 21 Apr 2009, 04:12 PM
Okay, well, at least glad to know I was onto the best possible solution!  Thanks.  Thanks for the reference links.
Tags
General Discussions
Asked by
Scott
Top achievements
Rank 1
Answers by
Steve
Telerik team
Scott
Top achievements
Rank 1
Share this question
or