Control the bar chart width by an expression in SQL Reporting Services

Applies to: Nevron Chart for Reporting Services (SSRS 2005 and 2008)

How to control the bar chart width by an expression in SQL Reporting Services?

In Nevron Chart for SQL Reporting Services, you can currently control the bar chart width by an expression with custom code injection. To apply different bar width from code:

1. Go to the code tab



2. Define a custom code parameter named "BarWidth" that evaluates to some SSRS expression. For example:
Name: "BarWidth"
Value: "=30"



3. Use the following code:

[C#]
using System;
using System.Drawing;
using Nevron.GraphicsCore;
using Nevron.Chart;
using Nevron.ReportingServices;
 
namespace MyNamespace
{
      /// <summary>
      /// Sample class
      /// </summary>
      public class MyClass
      {
            /// <summary>
            /// Main entry point
            /// </summary>
            /// <param name="context"></param>
            public static void RSMain(NRSChartCodeContext context)
            {
                  if (context.Document.Charts.Count == 0 ||
                        context.Document.Charts[0].Series.Count == 0)
                        return;
                  NChart chart = context.Document.Charts[0];
                  NBarSeries barWidth = chart.Series[0] as NBarSeries;
                   
                  barWidth.WidthPercent = context.GetSingleParameter("BarWidth");
            }
      }
}

Article ID: 186, Created On: 4/8/2011, Modified: 4/8/2011