Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
275
How to create a zero centered linear gauge
posted

The specific gauge I'm currently working on needs a range of -4.3 to +4.3 with zero at the center.

I can get most of this by setting the axis start value at zero and the axis end value at 8.6 and then setting the marker value to the calculated value + 4.3. What I haven't been able to figure out is how to setup the MajorTickmarks to work correctly with this.

Any suggestions?

Thanks, Dave

Parents
  • 28496
    Offline posted

    how about using 3 scales?

    RadialGauge rg = new RadialGauge();
    rg.Scales.Add(new RadialGaugeScale());
    rg.Scales[0].Axis = new NumericAxis(-4.3, -4.0, 0.3);
    rg.Scales.Add(new RadialGaugeScale());
    rg.Scales[1].Axis = new NumericAxis(-4.0, 4.0, 1.0);
    rg.Scales.Add(new RadialGaugeScale());
    rg.Scales[2].Axis = new NumericAxis(4.0, 4.3, 0.3);


    BrushElement labelsBrushElement = new SolidFillBrushElement(Color.Black);
    BrushElement tickmarksBrushElement = new SolidFillBrushElement(Color.Green);

    rg.Scales[0].Labels.BrushElement = rg.Scales[1].Labels.BrushElement = rg.Scales[2].Labels.BrushElement = labelsBrushElement;
    rg.Scales[0].MajorTickmarks.BrushElement = rg.Scales[1].MajorTickmarks.BrushElement = rg.Scales[2].MajorTickmarks.BrushElement = tickmarksBrushElement;

    rg.Scales[0].Labels.FormatString = rg.Scales[2].Labels.FormatString = "<DATA_VALUE:0.0>";
    rg.Scales[0].MajorTickmarks.PreTerminal = rg.Scales[0].Labels.PreTerminal = rg.Scales[2].MajorTickmarks.PostInitial = rg.Scales[2].Labels.PostInitial = .3;

    rg.Scales[0].MinorTickmarks.Visible = rg.Scales[1].MinorTickmarks.Visible = rg.Scales[2].MinorTickmarks.Visible = false;

    double startAngle = 120.0;
    double endAngle = 420.0;

    double degreesPerUnit = (endAngle - startAngle) / 8.6;

    // first scale (-4.3 to -4)
    rg.Scales[0].StartAngle = startAngle;
    rg.Scales[0].EndAngle = startAngle + degreesPerUnit * .3;

    // middle scale (-4 to +4)
    rg.Scales[1].StartAngle = rg.Scales[0].EndAngle;
    rg.Scales[1].EndAngle = rg.Scales[1].StartAngle + degreesPerUnit * 8.0;

    // last scale (+4 to +4.3)
    rg.Scales[2].StartAngle = rg.Scales[1].EndAngle;
    rg.Scales[2].EndAngle = rg.Scales[2].StartAngle + degreesPerUnit * .3;

    ultraGauge1.Gauges.Add(rg);

Reply Children
No Data