Nevron Forum

How to detect and avoid the axis lables overlapping?

https://www.nevron.com/Forum/Topic5587.aspx

By bargitta chen - Monday, September 19, 2011

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.

By Nevron Support - Monday, September 19, 2011

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.

By bargitta chen - Tuesday, September 20, 2011

Thank you team, very helpful!