Exemple #1
0
        private void UpdateScale()
        {
            NAxis     primaryY      = nChartControl1.Charts[0].Axis(StandardAxis.PrimaryY);
            NRange1DD hotZoneRange  = new NRange1DD(Convert.ToDouble(HotZoneBeginDropDownList.SelectedValue), 100);
            NRange1DD coldZoneRange = new NRange1DD(0, Convert.ToDouble(ColdZoneEndDropDownList.SelectedValue));

            NScaleSectionStyle hotZoneSection = new NScaleSectionStyle();

            hotZoneSection.Range                = hotZoneRange;
            hotZoneSection.LabelTextStyle       = new NTextStyle(new NFontStyle(), Color.Red);
            hotZoneSection.MajorTickStrokeStyle = new NStrokeStyle(1, Color.Red);
            hotZoneSection.RangeFillStyle       = new NColorFillStyle(Color.FromArgb(50, Color.Red));
            hotZoneSection.SetShowAtWall(ChartWallType.Back, true);

            NScaleSectionStyle coldZoneSection = new NScaleSectionStyle();

            coldZoneSection.Range                = coldZoneRange;
            coldZoneSection.LabelTextStyle       = new NTextStyle(new NFontStyle(), Color.Blue);
            coldZoneSection.MajorTickStrokeStyle = new NStrokeStyle(1, Color.Blue);
            coldZoneSection.RangeFillStyle       = new NColorFillStyle(Color.FromArgb(50, Color.Blue));
            coldZoneSection.SetShowAtWall(ChartWallType.Back, true);

            NStandardScaleConfigurator configurator = (NStandardScaleConfigurator)primaryY.ScaleConfigurator;

            configurator.Sections.Clear();
            configurator.Sections.Add(hotZoneSection);
            configurator.Sections.Add(coldZoneSection);

            // first use the scale configurator to output some definition
            primaryY.SynchronizeScaleWithConfigurator = true;
            primaryY.InvalidateScale();
            primaryY.UpdateScale();
            primaryY.SynchronizeScaleWithConfigurator = false;

            // manually program the scale
            NScaleLevel                    scaleLevel;
            NCustomScaleDecorator          customScaleDecorator;
            NScaleRangeDecorationAnchor    anchor;
            NScaleLevelSeparator           separator;
            NValueScaleLabel               label;
            NNumericDoubleStepRangeSampler rangeSampler;
            NClampedRangeSampler           clampedRangeSampler;
            NScaleTickFactory              tickFactory;
            NSampledScaleDecorator         sampledDecorator;;

            // create the hot zone

            // add a level separator
            scaleLevel           = new NScaleLevel();
            customScaleDecorator = new NCustomScaleDecorator();

            anchor    = new NScaleRangeDecorationAnchor(hotZoneRange);
            separator = new NScaleLevelSeparator(0, anchor, ScaleLevelShape.Line, null, new NStrokeStyle(1, Color.Red), new NLength(0), new NLength(0), new NLength(0), new NLength(0), null, null, null, false);
            customScaleDecorator.Decorations.Add(separator);

            // create a value scale label
            label        = new NValueScaleLabel();
            label.Text   = "Hot Zone";
            label.Anchor = new NRulerValueDecorationAnchor(HorzAlign.Right, new NLength(0));
            label.Offset = new NLength(6, NGraphicsUnit.Point);
            label.Style.TextStyle.FillStyle = new NColorFillStyle(Color.Red);
            label.Style.ContentAlignment    = ContentAlignment.TopRight;
            label.Style.Angle = new NScaleLabelAngle(ScaleLabelAngleMode.View, 90, true);

            customScaleDecorator.Decorations.Add(label);
            scaleLevel.Decorators.Add(customScaleDecorator);

            // add a some ticks
            rangeSampler = new NNumericDoubleStepRangeSampler(new NCustomNumericStepProvider(5));
            rangeSampler.UseCustomOrigin = true;
            rangeSampler.CustomOrigin    = 0;
            clampedRangeSampler          = new NClampedRangeSampler(rangeSampler, hotZoneRange);

            tickFactory = new NScaleTickFactory(0, ScaleTickShape.Line,
                                                new NLength(0),
                                                new NSizeL(new NLength(1), new NLength(5, NGraphicsUnit.Point)),
                                                new NConstValueProvider(new NColorFillStyle(Color.Red)),
                                                new NConstValueProvider(new NStrokeStyle(1, Color.Red)),
                                                HorzAlign.Left);

            sampledDecorator = new NSampledScaleDecorator(clampedRangeSampler, tickFactory);
            scaleLevel.Decorators.Add(sampledDecorator);

            // create the cold zone
            // add a level separator
            customScaleDecorator = new NCustomScaleDecorator();

            anchor    = new NScaleRangeDecorationAnchor(coldZoneRange);
            separator = new NScaleLevelSeparator(0, anchor, ScaleLevelShape.Line, null, new NStrokeStyle(1, Color.Blue));
            customScaleDecorator.Decorations.Add(separator);

            // create a value scale label
            label        = new NValueScaleLabel();
            label.Text   = "Cold Zone";
            label.Anchor = new NRulerValueDecorationAnchor(HorzAlign.Left, new NLength(0));
            label.Offset = new NLength(6, NGraphicsUnit.Point);
            label.Style.TextStyle.FillStyle = new NColorFillStyle(Color.Blue);
            label.Style.ContentAlignment    = ContentAlignment.TopLeft;
            label.Style.Angle = new NScaleLabelAngle(ScaleLabelAngleMode.View, 90, true);

            customScaleDecorator.Decorations.Add(label);
            scaleLevel.Decorators.Add(customScaleDecorator);

            // add a some ticks
            rangeSampler        = new NNumericDoubleStepRangeSampler(new NCustomNumericStepProvider(5));
            clampedRangeSampler = new NClampedRangeSampler(rangeSampler, coldZoneRange);

            tickFactory = new NScaleTickFactory(0, ScaleTickShape.Line,
                                                new NLength(0),
                                                new NSizeL(new NLength(1), new NLength(5, NGraphicsUnit.Point)),
                                                new NConstValueProvider(new NColorFillStyle(Color.Red)),
                                                new NConstValueProvider(new NStrokeStyle(1, Color.Blue)),
                                                HorzAlign.Left);

            sampledDecorator = new NSampledScaleDecorator(clampedRangeSampler, tickFactory);
            scaleLevel.Decorators.Add(sampledDecorator);

            primaryY.Scale.Levels.Add(scaleLevel);

            UpdateData(hotZoneRange, coldZoneRange);
        }
Exemple #2
0
        public override void Create()
        {
            nChartControl1.Panels.Clear();

            // set a chart title
            NLabel header = new NLabel("Gauge Custom Labels");

            header.TextStyle.FontStyle = new NFontStyle("Times New Roman", 18, System.Drawing.FontStyle.Italic);
            header.ContentAlignment    = ContentAlignment.BottomRight;
            header.Location            = new NPointL(new NLength(2, NRelativeUnit.ParentPercentage), new NLength(2, NRelativeUnit.ParentPercentage));

            nChartControl1.Panels.Add(header);

            // create the radial gauge
            NRadialGaugePanel radialGauge = new NRadialGaugePanel();

            radialGauge.Location    = new NPointL(new NLength(10, NRelativeUnit.ParentPercentage), new NLength(12, NRelativeUnit.ParentPercentage));
            radialGauge.Size        = new NSizeL(new NLength(80, NRelativeUnit.ParentPercentage), new NLength(80, NRelativeUnit.ParentPercentage));
            radialGauge.PaintEffect = new NGlassEffectStyle();
            radialGauge.BorderStyle = new NEdgeBorderStyle(BorderShape.Auto);

            NAdvancedGradientFillStyle advGradient = new NAdvancedGradientFillStyle();

            advGradient.BackgroundColor = Color.Black;
            advGradient.Points.Add(new NAdvancedGradientPoint(Color.White, 10, 10, 0, 100, AGPointShape.Circle));
            radialGauge.BackgroundFillStyle = advGradient;

            radialGauge.SweepAngle = 360;
            radialGauge.BeginAngle = -90;
            nChartControl1.Panels.Add(radialGauge);

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

            axis.Range = new NRange1DD(0, 60);
            axis.Anchor.RulerOrientation = RulerOrientation.Right;
            axis.Anchor = new NDockGaugeAxisAnchor(GaugeAxisDockZone.Top, true, RulerOrientation.Right, 0, 100);
            NLinearScaleConfigurator scale = (NLinearScaleConfigurator)axis.ScaleConfigurator;

            NScaleStripStyle stripStyle = new NScaleStripStyle(new NColorFillStyle(Color.FromArgb(20, Color.LightGray)), null, true, 0, 0, 1, 1);

            stripStyle.SetShowAtWall(ChartWallType.Back, true);
            stripStyle.Interlaced = true;
            scale.StripStyles.Add(stripStyle);
            scale.MinorTickCount = 4;
            scale.MajorTickMode  = MajorTickMode.CustomStep;
            scale.CustomStep     = 5.0f;
            scale.SetPredefinedScaleStyle(PredefinedScaleStyle.Watch);
            scale.OuterMajorTickStyle.FillStyle = new NGradientFillStyle(Color.White, Color.Beige);
            scale.OuterMajorTickStyle.LineStyle = new NStrokeStyle(Color.DarkGray);
            scale.OuterMajorTickStyle.Length    = new NLength(14);
            scale.RulerStyle.FillStyle          = new NColorFillStyle(Color.FromArgb(50, Color.Silver));
            scale.RulerStyle.BorderStyle        = new NStrokeStyle(Color.Beige);

            axis.UpdateScale();
            axis.SynchronizeScaleWithConfigurator = false;

            NTextStyle textStyle1 = new NTextStyle();

            textStyle1.FillStyle        = new NColorFillStyle(Color.White);
            textStyle1.BorderStyle      = new NStrokeStyle(1, Color.Beige);
            textStyle1.FontStyle.Style  = System.Drawing.FontStyle.Bold;
            textStyle1.FontStyle.EmSize = new NLength(22);
            NScaleLabelAngle angle = new NScaleLabelAngle(ScaleLabelAngleMode.Scale, 0);

            NTextStyle textStyle2 = new NTextStyle();

            textStyle2.FillStyle        = new NColorFillStyle(Color.White);
            textStyle2.BorderStyle      = new NStrokeStyle(1, Color.Beige);
            textStyle2.FontStyle.Style  = System.Drawing.FontStyle.Bold;
            textStyle2.FontStyle.EmSize = new NLength(12);

            NCustomScaleDecorator customDecorator = new NCustomScaleDecorator();

            NValueScaleLabelStyle style1 = new NValueScaleLabelStyle(textStyle1, ContentAlignment.MiddleCenter, angle, new NLength(0));
            NValueScaleLabelStyle style2 = new NValueScaleLabelStyle(textStyle2, ContentAlignment.MiddleCenter, angle, new NLength(0));

            for (int i = 12; i > 0; i--)
            {
                string           text = NSystem.IntToRoman(i);
                NValueScaleLabel hourLabel;

                if (i % 3 == 0)
                {
                    hourLabel = new NValueScaleLabel(new NScaleValueDecorationAnchor(i * 5), text, (NValueScaleLabelStyle)style1.Clone());
                }
                else
                {
                    hourLabel = new NValueScaleLabel(new NScaleValueDecorationAnchor(i * 5), text, (NValueScaleLabelStyle)style2.Clone());
                }

                customDecorator.Decorations.Add(hourLabel);
            }

            NScaleLevel textLevel = (NScaleLevel)axis.Scale.Levels[1];

            textLevel.Decorators.Clear();
            textLevel.Decorators.Add(customDecorator);

            m_HoursArrow                         = new NNeedleValueIndicator();
            m_HoursArrow.Value                   = 79;
            m_HoursArrow.Shape.FillStyle         = new NGradientFillStyle(GradientStyle.Horizontal, GradientVariant.Variant1, Color.White, Color.Red);
            m_HoursArrow.Shape.StrokeStyle.Color = Color.Red;
            m_HoursArrow.OffsetOriginMode        = IndicatorOffsetOriginMode.ScaleEnd;
            m_HoursArrow.OffsetFromScale         = new NLength(30);
            m_HoursArrow.Width                   = new NLength(8);
            radialGauge.Indicators.Add(m_HoursArrow);

            m_MinituesArrow                         = new NNeedleValueIndicator();
            m_MinituesArrow.Value                   = 79;
            m_MinituesArrow.Shape.FillStyle         = new NGradientFillStyle(GradientStyle.Horizontal, GradientVariant.Variant1, Color.White, Color.Red);
            m_MinituesArrow.Shape.StrokeStyle.Color = Color.Red;
            m_MinituesArrow.OffsetOriginMode        = IndicatorOffsetOriginMode.ScaleEnd;
            m_MinituesArrow.OffsetFromScale         = new NLength(30);
            m_MinituesArrow.Width                   = new NLength(5);
            radialGauge.Indicators.Add(m_MinituesArrow);

            m_SecondsArrow                         = new NNeedleValueIndicator();
            m_SecondsArrow.Value                   = 79;
            m_SecondsArrow.Shape.FillStyle         = new NGradientFillStyle(GradientStyle.Horizontal, GradientVariant.Variant1, Color.White, Color.Red);
            m_MinituesArrow.OffsetOriginMode       = IndicatorOffsetOriginMode.ScaleEnd;
            m_SecondsArrow.Shape.StrokeStyle.Color = Color.Red;
            m_SecondsArrow.OffsetFromScale         = new NLength(10);
            m_SecondsArrow.Width                   = new NLength(1);
            radialGauge.Indicators.Add(m_SecondsArrow);

            //nChartControl1.AutoRefresh = true;
            SynchronizeWithTime();

            m_Timer           = new DispatcherTimer();
            m_Timer.Interval  = new TimeSpan(1000);
            m_Timer.Tick     += m_Timer_Tick;
            m_Timer.IsEnabled = true;
            m_Timer.Start();
        }