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

Get Rid of Nan and display a friendly message

4 Answers 210 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Rahul
Top achievements
Rank 1
Rahul asked on 15 Jan 2013, 12:22 PM
Hi ,

I am using telerik rad charts in my application. When the data values are 0 for Pie Chart. The Chart is not displayed instead Nan is displayed. I want to get rid of this Nan and show a friendly message like "No Data available". Please help me in this.


Thanks,

4 Answers, 1 is accepted

Sort by
0
Rahul
Top achievements
Rank 1
answered on 16 Jan 2013, 09:19 AM
Hi,

Please help me in this as this is really very important for us.

Thanks,
0
Nikolay
Telerik team
answered on 17 Jan 2013, 08:55 AM
Hi Rahul,

When a pie chart has zero or null values, it would not display a Nan message, here is a sample code snippet :
protected void Page_Load(object sender, EventArgs e)
        {
            var series = new ChartSeries();
            series.Type = ChartSeriesType.Pie;
            var data = new List<SomeInfo>();
            for (int i = 0; i < 5; i++)
            {
                data.Add(new SomeInfo() { Val = null, Name = "0" + i });
            }
            series.DataYColumn = "Val";
            series.Appearance.LegendDisplayMode = ChartSeriesLegendDisplayMode.ItemLabels;
 
            radChart.Series.Add(series);
            radChart.DataSource = data;
            radChart.DataBind();
        }
    }
 
    public class SomeInfo
    {
        public double? Val { get; set; }
        public string Name { get; set; }
    }

Whether you set null values or 0 values, there simply wouldn't be a chart displayed.

In any case, you can set a chart empty message string in the following manner :
this.radChart.PlotArea.EmptySeriesMessage.TextBlock.Text = "No Data Available";

Hope this helps.

All the best,
Nikolay
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Rahul
Top achievements
Rank 1
answered on 18 Jan 2013, 09:41 AM
Hi,

The following solution only works when datasource is null and not the datasourrce values are 0.

this.radChart.PlotArea.EmptySeriesMessage.TextBlock.Text = "No Data Available";

Thanks,
0
Nikolay
Telerik team
answered on 22 Jan 2013, 08:56 AM
Hi,

In order to display the EmptySeriesMessage in such a case, where you have actual data for the series, but it could be 0 ( or null ) you would have to alter the chart DataSource in this manner :
radChart.DataSource = data.All(c => c.Val == 0) ? null : data;

This way, you would get the message when all data points have a value of 0.

All the best,
Nikolay
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Chart (Obsolete)
Asked by
Rahul
Top achievements
Rank 1
Answers by
Rahul
Top achievements
Rank 1
Nikolay
Telerik team
Share this question
or