Get Rid of Nan and display a friendly message

Thread is closed for posting
5 posts, 0 answers
  1. Rahul
    Rahul avatar
    8 posts
    Member since:
    May 2012

    Posted 15 Jan 2013 Link to this post

    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,
  2. Rahul
    Rahul avatar
    8 posts
    Member since:
    May 2012

    Posted 16 Jan 2013 Link to this post

    Hi,

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

    Thanks,
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Nikolay
    Admin
    Nikolay avatar
    385 posts

    Posted 17 Jan 2013 Link to this post

    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.
  5. Rahul
    Rahul avatar
    8 posts
    Member since:
    May 2012

    Posted 18 Jan 2013 Link to this post

    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,
  6. Nikolay
    Admin
    Nikolay avatar
    385 posts

    Posted 22 Jan 2013 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017