Wrap X Axis labels in a horizontal chart


https://www.nevron.com/Forum/Topic7818.aspx
Print Topic | Close Window

By Bob Smith - 11 Years Ago

I have a horizontal bar chart and I would like to force the X Axis labels to wrap as they are quite long. I can't find a setting in the configuration for it but I am hoping that I might be able to use code injection to wrap the labels. It makes the chart quite wide and adds a lot of white space next to the chart.

I've attached a screenshot of my issue with important data blanked out.

By Nevron Support - 11 Years Ago
Hi Bob,

The following code snippet shows how to force X axis labels to wrap so that their width does not exceed 100 pixels:

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

NRangeScaleLabelStyle labelStyle = new NRangeScaleLabelStyle();
labelStyle.TickMode = RangeLabelTickMode.None;
labelStyle.WrapText = true;
labelStyle.MaxWidth = new NLength(100, NGraphicsUnit.Pixel);
labelStyle.TextStyle.StringFormatStyle.HorzAlign = Nevron.HorzAlign.Right;
scaleX.LabelStyle = labelStyle;

Hope this helps - let us know if you meet any problems...
By Bob Smith - 11 Years Ago

Thanks for getting back to me!

I always have a hard time debugging code injection routines as I don't have access to the .net libraries or visual studio at my office Here is the compile error I am receiving:

Compiling...

(1,1) : error CS0116: A namespace does not directly contain members such as fields or methods

(2,40) : error CS1518: Expected class, delegate, enum, interface, or struct

(5,27) : error CS1518: Expected class, delegate, enum, interface, or struct

Compiled with 3 error(s).

By Nevron Support - 11 Years Ago
Hi Bob,

In SSRS / SharePoint the code should look like:

using System;
using System.Drawing;
using Nevron.GraphicsCore;
using Nevron.Chart;
using Nevron.ReportingServices;

namespace MyNamespace
{
   ///
   /// Sample class
   ///

   public class MyClass
   {
      ///
      /// Main entry point
      ///

      ///
      public static void RSMain(NRSChartCodeContext context)
      {
         NChart chart = context.Document.Charts[0];
         
         NOrdinalScaleConfigurator scaleX = (NOrdinalScaleConfigurator)chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator;
         
         NRangeScaleLabelStyle labelStyle = new NRangeScaleLabelStyle();
         labelStyle.TickMode = RangeLabelTickMode.None;
         labelStyle.WrapText = true;
         labelStyle.MaxWidth = new NLength(100, NGraphicsUnit.Pixel);
         labelStyle.TextStyle.StringFormatStyle.HorzAlign = Nevron.HorzAlign.Right;
         scaleX.LabelStyle = labelStyle;
      }
   }
}
By Bob Smith - 11 Years Ago
Worked great! Thank you very much!