Profile Picture

Control visibility of Data Labels on Bar Chart

Posted By Brian Dalwood 12 Years Ago
Author
Message
Brian Dalwood
Posted 12 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: Forum Members
Last Active: 7 Years Ago
Posts: 6, Visits: 15
Hi,
I am trying to show/hide the Data Labels on a Column Bar chart through the code window but cannot get the C# syntax right. Can you help??
I want to hide the data label when the value of the bar = 0 and show it otherwise.

Can you please show some example code to do this.

I am getting the following errors when compiling

(66,23) : error CS0030: Cannot convert type 'Nevron.Chart.NDataSeriesDouble' to 'double'
(68,9) : error CS0029: Cannot implicitly convert type 'double' to 'bool'

from the below code snippet.

NDataSeriesDouble values = bar.Values;
double BarValue = (double)bar.Values;

if (BarValue = 0.0)
{
bar.DataLabelStyle.Format = "";
}
else
{
bar.DataLabelStyle.Format = "<value>";
}

Thanks
Brian

Nevron Support
Posted 12 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009
Hi Brian,

The first error means that bar.Values is a list of numbers and you cannot assign it to one variable of type double. You can use indexing to access a particular value in the list.

As for the second error, the comparison should be:

if (BarValue == 0.0)
{
}

These are only syntax errors, but in fact the correct approach is to leave the data label format to <value> and change the formatting of the value itself.

The following code demonstrates how to accomplish your requirement:

NChart chart = nChartControl1.Charts[0];
NBarSeries bar = new NBarSeries();
chart.Series.Add(bar);
bar.Values.AddRange(new double[] { 10, 20, 15, 33, 18, 0, 27, 2 });

bar.DataLabelStyle.Format = "<value>";
bar.Values.ValueFormatter = new Nevron.Dom.NNumericValueFormatter("#.###");

This is a full chart setup, in fact you only need the last two lines.




Best Regards,
Nevron Support Team





Similar Topics


Reading This Topic