Profile Picture

X-Axis labels on Bar-charts

Posted By Johan Carlsson 15 Years Ago
Author
Message
bob milanov
Posted 15 Years Ago
View Quick Profile
Supreme Being

Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)

Group: Forum Members
Last Active: 6 Months Ago
Posts: 153, Visits: 11

Hi Johan,

 

Yes - you can disable automatic labels and add custom ones, using a slightly different approach, which also allows you to have control over value, style, angle etc. The following code snippet shows how to achieve this:

 

NChart chart = nChartControl1.Charts[0];

 

NBarSeries bar = (NBarSeries)chart.Series.Add(SeriesType.Bar);

bar.Values.Add(10);

bar.Values.Add(20);

bar.Values.Add(30);

 

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

scale.AutoLabels = false;

 

NCustomValueLabel valLabel1 = new NCustomValueLabel();

valLabel1.Value = 0;

valLabel1.Text = "Red";

valLabel1.Style.TextStyle.FillStyle = new NColorFillStyle(Color.Red);

scale.CustomLabels.Add(valLabel1);

 

NCustomValueLabel valLabel2 = new NCustomValueLabel();

valLabel2.Value = 1;

valLabel2.Text = "Green";

valLabel2.Style.TextStyle.FillStyle = new NColorFillStyle(Color.Green);

scale.CustomLabels.Add(valLabel2);

 

NCustomValueLabel valLabel3 = new NCustomValueLabel();

valLabel3.Value = 2;

valLabel3.Text = "Blue";

valLabel3.Style.TextStyle.FillStyle = new NColorFillStyle(Color.Blue);

scale.CustomLabels.Add(valLabel3);

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

 

Best regards,
Bob



Johan Carlsson
Posted 15 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: Forum Members
Last Active: 15 Years Ago
Posts: 2, Visits: 1

It sure did, thanks a lot guys!

It possible that this is mentioned in the documentation (although I'm not able to find "All examples" neither locally on my computer nor on the Nevron page), but is it also possible to modify the color of these new X-labels?

Cheers, Johan



bob milanov
Posted 15 Years Ago
View Quick Profile
Supreme Being

Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)

Group: Forum Members
Last Active: 6 Months Ago
Posts: 153, Visits: 11

Thank you David for answering this question. Jonah - sorry I did't reply earlier - must have missed the post...



David Huxtable
Posted 15 Years Ago
View Quick Profile
Junior Member

Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)

Group: Forum Members
Last Active: 15 Years Ago
Posts: 13, Visits: 1
Good Morning Johan,

I believe All Examples -> Axes -> General -> Axes Labels contains what you are looking for.

Ensure you have set the AutoLabels property of your scale configurator to false.

Next execute your scaleconfigurator's Clear() method to ensure the labels of the x axis are removed and 1, 2, 3...etc are not displayed.

Finally add your desired x axis label values to your scale configurator's Labels enumeration.

For example:

// Create a linear scale configurator object and apply it to the primary x axis.
NLinearScaleConfigurator scaleXConfig = (NLinearScaleConfigurator)chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator;

// Ensure all your x-axis labels are displayed in the chart.
scaleConfigX.MajorTickMode = MajorTickMode.AutoMaxCount;

// Disable auto labels (this creates your 1, 2, 3..etc as far as I understand).
scaleConfigX.AutoLabels = false;

// Add your custom labels.
scaleConfigX.Labels.Add("Tomatoes");
scaleConfigX.Labels.Add("Oranges");
scaleConfigX.Labels.Add("Bananas");

I hope this post has helped Johan,

David.

Johan Carlsson
questionmark Posted 15 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: Forum Members
Last Active: 15 Years Ago
Posts: 2, Visits: 1
Hello,

In your Bar-chart gallery you have an example chart with "Tomatoes", "Oranges", "Bananas" etc. etc.. The X-Axis of this chart displays 1, 2, 3.. I was wondering if it is possible to make the X-Axis display "Tomatoes", "Oranges" instead of numbers.. And if so, how do you do it?

Regards, Johan



Similar Topics


Reading This Topic