Add a label on top of each row for floatBar chart


Author
Message
Nevron Support
Nevron Support
Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)
Group: Administrators
Posts: 3.1K, Visits: 4.2K

Hi Clare,

You should populate either the axis labels or the data labels series for each bar - for example:

// 1. Modify category labels of primary x axis

NOrdinalScaleConfigurator ordinalScale = chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator as NOrdinalScaleConfigurator;

if (ordinalScale != null)

{

ordinalScale.AutoLabels = false;


// for each category add a label here

ordinalScale.Labels.Clear();

ordinalScale.Labels.Add("Category 1");

ordinalScale.Labels.Add("Category 2");

ordinalScale.Labels.Add("Category 3");

}

// 2. Modify data labels per data point

NBarSeries barSeries = new NBarSeries();

barSeries.Labels.Clear();

barSeries.Labels[0] = "Some Label For Bar 1";

barSeries.Labels[1] = "Some Label For Bar 2";

// etc.

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



Best Regards,
Nevron Support Team


Clare Moore
Clare Moore
Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)
Group: Forum Members
Posts: 22, Visits: 1

Here is my code, ignore the label values i'm hard coding them for now

for (int i = 0; i < bar.BeginValues.Count; i++)

{

float val = (100 / bar.BeginValues.Count) * i;

NLabel title = new NLabel("7:00:00");

title.TextStyle.FontStyle = new NFontStyle("Arial", 10, FontStyle.Italic);

title.Location = new NPointL(new NLength(3, NRelativeUnit.ParentPercentage), new NLength(val, NRelativeUnit.ParentPercentage));

title.TextStyle.BorderStyle.Width = new NLength(0);

title.Margins = new NMarginsL(0, 0, 0, 0);

title.ContentAlignment = ContentAlignment.MiddleCenter;

chart.ChildPanels.Add(title);

NLabel othertitle = new NLabel("8:12:00");

othertitle.TextStyle.FontStyle = new NFontStyle("Arial", 10, FontStyle.Italic);

othertitle.Location = new NPointL(new NLength(50, NRelativeUnit.ParentPercentage), new NLength(val, NRelativeUnit.ParentPercentage));

othertitle.Margins = new NMarginsL(0, 0, 0, 0);

othertitle.TextStyle.BorderStyle.Width = new NLength(0);

othertitle.ContentAlignment = ContentAlignment.MiddleCenter;

chart.ChildPanels.Add(othertitle);

}

}

 

What i was hoping to achieve was for a label to appear over each bar but it ends up looking like the attached image


Attachments
LabelPositioning.jpg (207 views, 74.00 KB)
Nevron Support
Nevron Support
Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)
Group: Administrators
Posts: 3.1K, Visits: 4.2K

Hi Clare,

Can you post the code for review?



Best Regards,
Nevron Support Team


Clare Moore
Clare Moore
Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)
Group: Forum Members
Posts: 22, Visits: 1

I have a (horizontal) float bar chart, and i have some values that i'd like to display in labels on top of the bars.

Because my data is grouped, each row is actually made up of quite a few datapoints (otherwise i'd just use the data label).

Is there a way to display one label for each row, on the exact location of each row??

I have tried writing some code that figures out how many categories i have, and tried to position labels by calculating where they should go for each category - as a percentage of the total height, but this doesnt seem to be working out.


GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search