Nevron Forum

Display Message when Data Source for Line Chart is empty

https://www.nevron.com/Forum/Topic5899.aspx

By Bhumi Patel - Tuesday, November 29, 2011

Hi,

I am displaying a timely data in Line chart from database using dataset. So if data is not available at some point of time, my dataset is empty. Is there any way I can display a message instead of chart as shown in below image??


Thanks,
Bhumi
By Nevron Support - Wednesday, November 30, 2011

Hi Bhumi,

Yes - you can conditionally add the chart to the control panels collection - the following code snippet shows how to achieve such behaviour:

  private void UpdateChart()
  {
   nChartControl1.Panels.Clear();

   // create a chart that is not added to the control
   NCartesianChart chart = new NCartesianChart();

   NBarSeries bar =new NBarSeries();

   // feed data (in this case the chart will have
   // some data points randomly)
   Random rand  = new Random();
   if ((rand.Next() % 2) == 1)
   {
    bar.Values.Add(10);
    bar.Values.Add(20);
    bar.Values.Add(30);
   }

   chart.Series.Add(bar);

   // check if there is data and add the chart panel
   if (bar.Values.Count == 0)
   {
    NLabel label = new NLabel("There is no data");
    label.ContentAlignment = ContentAlignment.MiddleCenter;
    label.Location = new NPointL(new NLength(50, NRelativeUnit.ParentPercentage), new NLength(50, NRelativeUnit.ParentPercentage));
    nChartControl1.Panels.Add(label);
   }
   else
   {
    nChartControl1.Panels.Add(chart);
   }

   nChartControl1.Refresh();
  }

Hope this helps - let us know if you meet any problems...

By Bhumi Patel - Monday, December 5, 2011

Thank you. Its working perfectly!!

-Bhumi