Set the color of the pointer based on the SSRS Gauge range

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

How to set the color of the pointer based on the SSRS Gauge range?

In Nevron Gauge for SQL Server Reporting Services you can change the color of a gauge pointer(s) (needle or marker) when the pointer is in specific range. This feature can be used as another way to indicate a specific status based on the values passed to the gauge (similar to the Gauge State Indicator).



Let’s say that we have added 3 ranges with different fill styles (Green, Yellow and Red) to a radial gauge:



The following example code will check for the Indicators (Value Indicators and Range Indicators) and will color the pointer (gauge needle) when it is in specific gauge range, using the color of this range. The code will do the same with the gauge Cap.

[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(NRSGaugeCodeContext context)
        {
            // check if gauge document contains gauges
            if (context.Document.Gauges.Count == 0)
                return;
  
            // the needle indicator is after the range
            NGaugePanel gauge = context.Document.Gauges[0] as NGaugePanel;
            if (gauge == null || gauge.Indicators.Count == 0)
                return;
  
            NRadialGaugePanel radialGauge = gauge as NRadialGaugePanel;
            int indicatorCount = gauge.Indicators.Count;
            NValueIndicator needle = null;
  
            for (int i = 0; i < indicatorCount; i++)
            {
                needle = gauge.Indicators[i] as NValueIndicator;
  
                if (needle != null)
                    break;
            }
  
            if (needle == null)
                return;
  
            int rangIndicatorIndex = 0;
  
            for (int i = 0; i < indicatorCount; i++)
            {
                NRangeIndicator rangeIndicator = gauge.Indicators[i] as NRangeIndicator;
  
                if (rangeIndicator != null)
                {
                    NRange1DD range = new NRange1DD(rangeIndicator.Origin, rangeIndicator.Value);
                    range.Normalize();
  
                    // if indicator value is contained by the range change its color to red
                    if (range.Contains(needle.Value))
                    {
                        //needle.Shape.FillStyle = GetFillStyleForRange(rangIndicatorIndex);
                        needle.Shape.FillStyle = rangeIndicator.FillStyle;
                        if (radialGauge != null)
                        {
                            //radialGauge.CapStyle.Shape.FillStyle = GetFillStyleForRange(rangIndicatorIndex);
                            radialGauge.CapStyle.Shape.FillStyle = rangeIndicator.FillStyle;
                        }
  
                        break;
                    }
  
                    rangIndicatorIndex++;
                }
            }
        }
  
        //static NFillStyle GetFillStyleForRange(int rangeIndex)
        //{
        //    switch (rangeIndex)
        //    {
        //        case 0:
        //            return new NColorFillStyle(Color.Green);
  
        //        case 1:
        //            return new NColorFillStyle(Color.Yellow);
  
        //        case 2:
        //            return new NColorFillStyle(Color.Red);
  
        //        default:
        //            return new NColorFillStyle(Color.Black);
        //    }
        //}
    }
}

The following example code will check for the Indicators (Value Indicators and Range Indicators) and will color the pointer (gauge needle) when it is in specific gauge range, using the color of this range. The code will do the same with the gauge Cap.

Article ID: 215, Created On: 3/22/2012, Modified: 3/22/2012