How to detect and avoid the axis lables overlapping?


Author
Message
bargitta chen
bargitta chen
Junior Member (18 reputation)Junior Member (18 reputation)Junior Member (18 reputation)Junior Member (18 reputation)Junior Member (18 reputation)Junior Member (18 reputation)Junior Member (18 reputation)Junior Member (18 reputation)Junior Member (18 reputation)
Group: Forum Members
Posts: 18, Visits: 1

Dear experts,

Currently, I am using bar chart. When the label of each bar is too long, I want to show it tilted or in several lines as the attachment (like the one in excel). But I do not know how to detect such overlapping lables and tilt them propertly.

I do appreciate your help. Thanks in advance.


Attachments
barchart.jpg (78 views, 60.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 Bargitta,

You can actually achieve both outlooks - the following code snippets show how to have automatically rotated labels and automatically wrapped labels (we recommend the second option as horizontal texts are easier to read):

   NCartesianChart chart = (NCartesianChart)nChartControl1.Charts[0];

   NBarSeries bar = new NBarSeries();
   bar.Values.Add(10);
   bar.Values.Add(20);
   bar.Values.Add(30);

   chart.Series.Add(bar);

   NOrdinalScaleConfigurator scaleX = chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator as NOrdinalScaleConfigurator;
   scaleX.AutoLabels = false;

   scaleX.Labels.Add("Tabular Design and Analysis");
   scaleX.Labels.Add("Well Path Design");
   scaleX.Labels.Add("Drilling Engeneering");

   // option 1 - use value labels and rotate 30 or 45
   scaleX.LabelStyle.ContentAlignment = ContentAlignment.TopCenter;
   scaleX.LabelFitModes = new LabelFitMode[] { LabelFitMode.Rotate30, LabelFitMode.AutoScale };
   scaleX.LabelStyle.Angle = new NScaleLabelAngle(ScaleLabelAngleMode.Scale, 0, false);

   // option 2 (recommended) - use value labels and rotate 30 or 45
   NRangeScaleLabelStyle rangeScaleLabelStyle = new NRangeScaleLabelStyle();
   rangeScaleLabelStyle.TickMode = RangeLabelTickMode.None;
   rangeScaleLabelStyle.WrapText = true;
   scaleX.LabelStyle = rangeScaleLabelStyle;

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



Best Regards,
Nevron Support Team


bargitta chen
bargitta chen
Junior Member (18 reputation)Junior Member (18 reputation)Junior Member (18 reputation)Junior Member (18 reputation)Junior Member (18 reputation)Junior Member (18 reputation)Junior Member (18 reputation)Junior Member (18 reputation)Junior Member (18 reputation)
Group: Forum Members
Posts: 18, Visits: 1
Thank you team, very helpful!
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