Nevron Vision for SQL Server Reporting Services
Gauge / Code Embedding
In This Topic
    Code Embedding
    In This Topic

    The component allows you to modify every aspect of the visualized gauge image through custom C# code. This feature is useful when the settings exposed through the designer are not enough to produce the desired gauge appearance. This topic describes how to take advantage of this feature. Note that the code used here uses the Nevron Chart for .NET API, so some familiarity with it is recommended.

    The component designer contains a tab called "Code" that allows you to type code, configure custom parameters and add referenced assemblies that can be used by your code. The following sections describe how to achieve these goals. The sample code below assumes that your are working with the Code Embedding example shipped with the control.

    Adding Code with Entry Point

    The easiest way to start using the code embedding feature is to load an entry point template:

    1. Go to the Code tab

    2. Select File\New

    3. Select "Entry Point" from the templates list and click Ok.

    The designer will load a simple C# code that contains an entry point that the component will call at runtime:

    C#
    Copy Code

    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(NRSGaugeCodeContext context)
    {
    }
    }
    }


    Adding Custom Parameters

    Custom parameters are name/value pairs that allow you to associate a name with a SSRS expression. Adding custom parameters is explained in the chart Code Embedding topic and is essentially the same as with the chart report item.

     

    Extending the Code

    1. Extend the code with the following:

    C#
    Copy Code

    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(NRSGaugeCodeContext context)
    {
    // check if gauge document contains gauges
    if (context.Document.Gauges.Count == 0)
    return;

    // the needle indicator is inserted after the range
    NGaugePanel gauge = context.Document.Gauges[0] as NGaugePanel;
    if (gauge.Indicators.Count == 0)
    return;

    NValueIndicator indicator = gauge.Indicators[1] as NValueIndicator;
    if (indicator == null)
    return;

    NRange1DD range = new NRange1DD(80, 100);

    // if indicator value is contained by the range
    // change its color to red
    if (range.Contains(indicator.Value))
    {
    indicator.Shape.FillStyle =
    new NGradientFillStyle(GradientStyle.Vertical, GradientVariant.Variant2, Color.Red, Color.Yellow);
    }
    }
    }
    }

    The "context" parameter passed to the main entry point has a property called Document. This property allows you to access the chart document generated by the SSRS gauge template. The document fully exposes the Nevron Chart for .NET API and allows for full control over the gauge appearance.