X-Axis labels on Bar-charts


Author
Message
Johan Carlsson
Johan Carlsson
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
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
Reply
Blagovest Milanov
Blagovest Milanov
Supreme Being (148 reputation)Supreme Being (148 reputation)Supreme Being (148 reputation)Supreme Being (148 reputation)Supreme Being (148 reputation)Supreme Being (148 reputation)Supreme Being (148 reputation)Supreme Being (148 reputation)Supreme Being (148 reputation)
Group: Forum Members
Posts: 154, Visits: 15

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


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