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

(Solved) How to use NULL-s with Charts

0 Answers 424 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
kahuna
Top achievements
Rank 1
kahuna asked on 23 May 2012, 05:35 PM

EDIT:  Come on Telerik ... stop trying to sell your products & support so much, and actually care about the end-user : us developers. There is no reason why I shouldn't be able to post a solution showing how to solve the buggy behavior with your product. However, since Telerik doesn't like people helping out other people, here is a direct link to the ZIP file (which I cannot upload here, since it's not a gif, jpg, jpeg or png): http://bbarstow.relyonmedia.com/TelerikReportingChartsExamples.zip

So, you've always wanted to use a data source that had NULL values in it as the source for your charts. But the Telerik.Reporting.Chart doesn't handle null-s very well et all.

Solves these problems with Telerik Line & Bar (maybe others) charts using null-s:

  • Hide data point / data point label when value is null. (I.e. don't approximate and don't show 0)
  • Fixes "Cannot set Column 'myCol' to null. Please use DBNull instead" error

See sample Visual Studio 2010 solution which shows a line and a bar chart using a data table that has a couple of null-s.

-Blaise

(this is also more or less a response / extension to the no-longer-working hacks posted at http://www.telerik.com/community/forums/reporting/telerik-reporting/cannot-set-column-mycol-to-null-please-use-dbnull-instead.aspx)

(Quote from support ticket:

"I got it to work by creating all charts in code-behind. This shows that the 'designer mode' is next to useless, because the same functionality cannot be achieved by using the designer. I also had to use different steps to get the functionality to work correctly with both bar and line charts.

For both chart types the following steps worked:

1. In Chart_NeedDataSource event, loop through each row (create ChartSeries) and column in DataTable. When adding each ChartSeriesItem, if the value to add = DBNull.Value then use ‘ChartSeries.AddItem(new ChartSeriesItem(true))’ (Otherwise, add chart series item normally, i.e. ‘ChartSeries.AddItem(new ChartSeriesItem(5.0, “5”))’

2. After adding all ChartSeries (data) to the chart, then loop through each ChartSeriesItem in all Chart.Series (nested ‘foreach’.) When looping, we check if ‘ChartSeriesItem.Empty’ and when true, we now know that we have a null value and to handle that appropriately. For bar charts we set ‘ChartSeriesItem.Visible = false;’ and for line charts we set ‘ChartSeriesItem.Label.Visible = false;’

The buggy behavior:

· After the back and forth, and much trial and error, I discovered that in the line charts, the buggy behavior was caused by using the setting “ChartSeries.Appearance.PointMark.Visible” Setting this to true causes all ChartSeriesItem.Label-s to show up, all the time. The point mark visibility should not have any effect on the ChartSeriesItem.Label visibility.

The suggested / desired behavior for null-s:

1. When using any data source, NULL values should always be added to the ChartSeries as an empty ChartSeriesItem. (In accordance with the suggested new EmptyValuesMode)

2. ChartSeries.Appearance.EmptyValue.Mode should have the option of being set to ‘EmptyValuesMode.Hide’. This new option would hide the point marks / connecting lines / label connectors & labels for all empty ChartSeriesItems. (I.e. for Bar Charts setting ‘ChartSeriesItem.Visible = false’, and for Line Charts ‘ChartSeriesItem.Label.Visible = false’)

3. Additionally, ‘Telerik.Reporting.Charting.Styles.EmtyValuesMode’ is spelt wrong, and should be ‘EmptyValuesMode’ (missing the “p” in Empty)

4. A demo project using a standard data source and null-s should be added to the documentation. A real life example showing how to implement null-s would be great.")

No answers yet. Maybe you can help?

Tags
General Discussions
Asked by
kahuna
Top achievements
Rank 1
Share this question
or