Nevron Forum

Bar Chart Labels

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

By Bhumi Patel - Thursday, April 19, 2012

Hi,

Is it possible to display Label for a bar when value is 0 else hide them?? Please review attached image to understand my point.

Thanks in advance!!

-Bhumi
By Nevron Support - Thursday, April 19, 2012

Hi Bhumi,

Yes - you need to assign a per data point label in this case - for example:

   NChart chart = nChartControl1.Charts[0];
   NBarSeries bar = new NBarSeries();

   
   bar.Values.Add(30);
   bar.Values.Add(31);
   bar.Values.Add(0);
   bar.Values.Add(33);
   bar.Values.Add(34);
   bar.Values.Add(35);
   bar.Values.Add(40);

   bar.DataLabelStyle.Format = "<label>";
   bar.DataLabelStyle.Visible = true;

   for (int i = 0; i < bar.Values.Count; i++)
   {
    if ((double)bar.Values[i] == 0)
    {
     bar.Labels.Add("Zero");
    }
    else
    {
     bar.Labels.Add(string.Empty);
    }
    
   }

   chart.Series.Add(bar);

Applies "Zero" to all data points with value 0 and empty string otherwise.

By Bhumi Patel - Wednesday, April 25, 2012

Thank you for your reply. It worked perfectly!!