Nevron Forum

how I create this gauge

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

By suwit sangsuwan - Thursday, May 27, 2010

please help me I would like to create this gauge
By Nevron Support - Thursday, May 27, 2010

Hello Suwit,

 

You need to drop a NChartControl on the form. Make sure that you have the following references added to your project:

Nevron.Chart.dll

Nevron.Chart.WinForm.dll

Nevron.Presentation.dll

Nevron.System.dll

 

The following code can help you achieve similar gauge:

 

using Nevron.Chart;

using Nevron.Chart.WinForm;

using Nevron.GraphicsCore;

 

private void Form1_Load(object sender, EventArgs e)

{

    nChartControl1.Panels.Clear();

 

    NRadialGaugePanel radialGauge = new NRadialGaugePanel();

    nChartControl1.Panels.Add(radialGauge);

 

    radialGauge.BeginAngle = 129;

    radialGauge.SweepAngle = 282;

 

    radialGauge.AutoBorder = RadialGaugeAutoBorder.RoundedOutline;

    radialGauge.CenterBorderRounding = new NLength(72);

    radialGauge.EdgeBorderRounding = new NLength(10);

 

    // Gauge cap style

    radialGauge.CapStyle.Visible = true;

    radialGauge.CapStyle.Size = new NSizeL(25, 25);

    radialGauge.CapStyle.Shape.FillStyle = new NGradientFillStyle(GradientStyle.DiagonalUp, GradientVariant.Variant1, Color.White, Color.DimGray);

    radialGauge.CapStyle.Shape.StrokeStyle.Color = Color.DarkGray;

 

    // apply background and glass effect to the gauge

    NEdgeBorderStyle borderStyle = new NEdgeBorderStyle(BorderShape.Auto);

    borderStyle.OuterBevelWidth = new NLength(8);

    borderStyle.OuterBevelFillStyle = new NGradientFillStyle(GradientStyle.Horizontal, GradientVariant.Variant4, Color.White, Color.Black);

    borderStyle.InnerBevelWidth = new NLength(4);

    borderStyle.InnerBevelFillStyle = new NGradientFillStyle(GradientStyle.Horizontal, GradientVariant.Variant3, Color.White, Color.DimGray);

    borderStyle.MiddleBevelWidth = new NLength(0);

    radialGauge.BorderStyle = borderStyle;

 

    NGlassEffectStyle glass = new NGlassEffectStyle();

    glass.CornerRounding = new NLength(10);

    glass.DarkColor = Color.FromArgb(200, Color.LightGray);

    glass.LightColor = Color.FromArgb(200, Color.White);

    glass.EdgeDepth = new NLength(6);

    glass.EdgeOffset = new NLength(3);

    glass.LightDirection = -39;

    glass.LightSpread = 66;

 

    radialGauge.PaintEffect = glass;

    radialGauge.BackgroundFillStyle = new NGradientFillStyle(GradientStyle.Horizontal, GradientVariant.Variant2, Color.WhiteSmoke, Color.DimGray);

 

    // add some indicators

    NNeedleValueIndicator needle = new NNeedleValueIndicator(67);

    needle.OffsetFromScale = new NLength(10);

    needle.Width = new NLength(10);

    needle.Shape.FillStyle = new NGradientFillStyle(GradientStyle.Horizontal, GradientVariant.Variant1, Color.White, Color.Red);

    needle.Shape.StrokeStyle.Color = Color.Red;

    radialGauge.Indicators.Add(needle);

 

    // configure axis

    NGaugeAxis axis = (NGaugeAxis)radialGauge.Axes[0];

 

    // modify the anchor so that labels appear after the scale

    axis.Anchor = new NDockGaugeAxisAnchor(GaugeAxisDockZone.Top, true, RulerOrientation.Left, 3, 97);

 

    // apply settings to the gauge scale

    NLinearScaleConfigurator linearScale = axis.ScaleConfigurator as NLinearScaleConfigurator;

    linearScale.SetPredefinedScaleStyle(PredefinedScaleStyle.PresentationNoStroke);

    linearScale.LabelFitModes = new LabelFitMode[0];

 

    CreateSection(radialGauge, linearScale, Color.LimeGreen, new NRange1DD(0, 30));

    CreateSection(radialGauge, linearScale, Color.Yellow, new NRange1DD(30, 70));

    CreateSection(radialGauge, linearScale, Color.Red, new NRange1DD(70, 100));

 

    NNumericDisplayPanel numericDisplay = CreateDisplayPanel();

    numericDisplay.Size = new NSizeL(100, 60);

    numericDisplay.Location = new NPointL(new NLength(50, NRelativeUnit.ParentPercentage),

                                            new NLength(55, NRelativeUnit.ParentPercentage));

    numericDisplay.ContentAlignment = ContentAlignment.BottomCenter;

    numericDisplay.UseAutomaticSize = false;

    numericDisplay.BoundsMode = BoundsMode.Fit;

    numericDisplay.BackgroundFillStyle = new NColorFillStyle(Color.Transparent);

    numericDisplay.Value = 12.22;

    radialGauge.ChildPanels.Add(numericDisplay);

}

 

private void CreateSection(NRadialGaugePanel radialGauge, NLinearScaleConfigurator scale, Color color, NRange1DD range)

{

    // add range indicator       

    NRangeIndicator indicator = new NRangeIndicator();

 

    indicator.Value = range.End;

    indicator.OriginMode = OriginMode.Custom;

    indicator.Origin = range.Begin;

    indicator.FillStyle = new NColorFillStyle(Color.FromArgb(225, color));

    indicator.OffsetFromScale = new NLength(0);

    indicator.BeginWidth = new NLength(10);

    indicator.EndWidth = new NLength(10);

    indicator.PaintOrder = IndicatorPaintOrder.BeforeScale;

    radialGauge.Indicators.Add(indicator);

 

    // add scale section

    NScaleSectionStyle scaleSection = new NScaleSectionStyle();

    scaleSection.Range = range;

    scaleSection.MajorGridStrokeStyle = new NStrokeStyle(color);

    scaleSection.MajorTickStrokeStyle = new NStrokeStyle(color);

    scaleSection.MinorTickStrokeStyle = new NStrokeStyle(1, color, LinePattern.Dot, 2, 1);

 

    NTextStyle labelStyle = new NTextStyle();

    labelStyle.FontStyle = new NFontStyle("Verdana", 12, FontStyle.Bold);

    scaleSection.LabelTextStyle = labelStyle;

    scale.Sections.Add(scaleSection);

 

    scale.RulerStyle.FillStyle.SetTransparencyPercent(40);

    scale.RulerStyle.BorderStyle.Width = new NLength(0);

}

 

private NNumericDisplayPanel CreateDisplayPanel()

{

    NNumericDisplayPanel numericDisplay = new NNumericDisplayPanel();

 

    numericDisplay.Value = 0;

    numericDisplay.CellCountMode = DisplayCellCountMode.Fixed;

    numericDisplay.CellCount = 7;

    numericDisplay.Margins = new NMarginsL(10, 10, 10, 10);

    numericDisplay.Padding = new NMarginsL(10, 10, 10, 10);

    numericDisplay.BackgroundFillStyle = new NColorFillStyle(Color.Black);

 

    // adjust cell fill styles

    numericDisplay.LitFillStyle = new NColorFillStyle(Color.DarkGray);

    numericDisplay.DimFillStyle = new NColorFillStyle(Color.Transparent);

    numericDisplay.DecimalLitFillStyle = new NColorFillStyle(Color.White);

    numericDisplay.DecimalDimFillStyle = new NColorFillStyle(Color.Transparent);

 

    return numericDisplay;

}

 

We hope this helps.

 

Kind regards,

Nevron Support Team

By Justin Short 1 - Thursday, May 27, 2010

Hi,

I'm trying to achieve the same effect in SSRS Vision. I have a gauge which I need to change the colour of the ruler fill to red amber green (exactly as you have in the picture).

I'm using the following in the code behind ...


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

// check if gauge document contains gauges
if (context.Document.Gauges.Count == 0)
return;

// the ruler is inserted after the range
NRadialGaugePanel gauge = context.Document.Gauges[0] as NRadialGaugePanel;
NGaugeAxis axis = (NGaugeAxis)gauge.Axes[0];
NLinearScaleConfigurator linear = axis.ScaleConfigurator as NLinearScaleConfigurator;

CreateSection(gauge, linear, Color.LimeGreen, new NRange1DD(0,30));
CreateSection(gauge, linear, Color.Yellow, new NRange1DD(30,70));
CreateSection(gauge, linear, Color.Red, new NRange1DD(70,100));
}

private void CreateSection(NRadialGaugePanel gauge, NLinearScaleConfigurator scale, Color color, NRange1DD range)
{
}

}
}



but it errors with

Compiling...
(33,1) : error CS0120: An object reference is required for the nonstatic field, method, or property 'MyNamespace.MyClass.CreateSection(Nevron.Chart.NRadialGaugePanel, Nevron.Chart.NLinearScaleConfigurator, System.Drawing.Color, Nevron.GraphicsCore.NRange1DD)'
Compiled with 1 error(s).

Any pointers much appreciated
Cheers, Justin
By Nevron Support - Thursday, May 27, 2010

Hi Justin,

 

The CreateSection function must be static as it called from the static RSMain:

 

private static void CreateSection(NRadialGaugePanel gauge, NLinearScaleConfigurator scale, Color color, NRange1DD range)

{

      // add range indicator

      NRangeIndicator indicator = new NRangeIndicator();

     

      indicator.Value = range.End;

      indicator.OriginMode = OriginMode.Custom;

      indicator.Origin = range.Begin;

      indicator.FillStyle = new NColorFillStyle(Color.FromArgb(225, color));

      indicator.OffsetFromScale = new NLength(0);

      indicator.BeginWidth = new NLength(10);

      indicator.EndWidth = new NLength(10);

      indicator.PaintOrder = IndicatorPaintOrder.BeforeScale;

      gauge.Indicators.Add(indicator);

     

      // add scale section

      NScaleSectionStyle scaleSection = new NScaleSectionStyle();

      scaleSection.Range = range;

      scaleSection.MajorGridStrokeStyle = new NStrokeStyle(color);

      scaleSection.MajorTickStrokeStyle = new NStrokeStyle(color);

      scaleSection.MinorTickStrokeStyle = new NStrokeStyle(1, color, LinePattern.Dot, 2, 1);

     

      NTextStyle labelStyle = new NTextStyle();

      labelStyle.FontStyle = new NFontStyle("Verdana", 12, FontStyle.Bold);

      scaleSection.LabelTextStyle = labelStyle;

      scale.Sections.Add(scaleSection);

     

      scale.RulerStyle.FillStyle.SetTransparencyPercent(40);

      scale.RulerStyle.BorderStyle.Width = new NLength(0);

}

 

Your requirement in SSRS can also be achieved without code injection. Take a look at the attached Gauge template and the gauge Ranges settings.

If you have any questions or need additional assistance, please let us know.

 

Best regards,

Nevron Support Team

By Justin Short 1 - Thursday, May 27, 2010

Thanks for the swift help on this.

I've managed to get it working successfully both ways - just what I needed!

Cheers, Justin
By suwit sangsuwan - Monday, May 31, 2010

thank you