public static void GenerateData(NXYScatterSeries xyScatterSeries, double value, int nCount, NRange1DD range)
        {
            xyScatterSeries.ClearDataPoints();
            DateTime dt = new DateTime(2009, 1, 5);

            for (int nIndex = 0; nIndex < nCount; nIndex++)
            {
                bool upward = false;

                if (range.Begin > value)
                {
                    upward = true;
                }
                else if (range.End < value)
                {
                    upward = false;
                }
                else
                {
                    upward = Random.NextDouble() > 0.5;
                }

                xyScatterSeries.Values.Add(value);

                if (upward)
                {
                    value += (2 + (Random.NextDouble() * 20));
                }
                else
                {
                    value -= (2 + (Random.NextDouble() * 20));
                }

                xyScatterSeries.XValues.Add(nIndex);
            }
        }
        /// <summary>
        /// Builds the attribute chart
        /// </summary>
        /// <param name="attributes">statistics for an attribute chart</param>
        private void BuildChart(IAttributeChartStats stats)
        {
            int nppoints = stats.Statistic.Length;
            double xstart = stats.TimeStart;
            double xincrement = stats.TimeSampleInterval;

            this.nControlChart.Panels.Clear();

            //
            // Set up chart title.
            //
            NLabel title = new NLabel();
            this.nControlChart.Panels.Add(title);
            title.Dock = DockStyle.Top;
            title.Padding = new NMarginsL(5, 8, 5, 4);
            title.Text = stats.ChartTitle;
            title.TextStyle.FontStyle = new NFontStyle("Verdana", 12, FontStyle.Bold | FontStyle.Italic);
            title.TextStyle.FillStyle = new NColorFillStyle(Color.FromArgb(68, 90, 108));

            //
            // Set up the chart
            //
            NChart chart = new NCartesianChart();
            this.nControlChart.Charts.Add(chart);
            chart.BoundsMode = BoundsMode.Stretch;
            chart.Dock = DockStyle.Fill;
            chart.Wall(ChartWallType.Back).FillStyle = new NGradientFillStyle(GradientStyle.Horizontal, GradientVariant.Variant2, Color.White, Color.FromArgb(233, 233, 255));
            chart.Padding = new NMarginsL(
                    new NLength(6, NRelativeUnit.ParentPercentage),
                    new NLength(6, NRelativeUnit.ParentPercentage),
                    new NLength(6, NRelativeUnit.ParentPercentage),
                    new NLength(6, NRelativeUnit.ParentPercentage));

            SetupChartAxes(chart, stats);

            //
            // First set up a point series for the outliers so it's on-top in z-order.
            //
            NPointSeries outlierPoints = new NPointSeries();
            chart.Series.Add(outlierPoints);

            // Name the series
            outlierPoints.Name = "Control Limit Violations";

            // Tell the series to regard the X values
            outlierPoints.UseXValues = true;

            // Points must fit in the chart area
            outlierPoints.InflateMargins = true;

            // No data labels
            outlierPoints.DataLabelStyle.Visible = false;

            // Set the point appearance properties
            outlierPoints.FillStyle = new NColorFillStyle(Color.Red);
            outlierPoints.BorderStyle = new NStrokeStyle(1.0f, Color.Black);
            outlierPoints.PointShape = PointShape.Cross;
            outlierPoints.Size = new NLength(6.0f);

            // Add the statistic
            for (int i = 0; i < nppoints; i++)
            {
                double statValue = stats.Statistic[i];

                // Do not display a marker if the point is an outlier
                if ((statValue > stats.UCL[i]) || (statValue < stats.LCL[i]))
                {
                    outlierPoints.XValues.Add(xstart + xincrement * i);
                    outlierPoints.Values.Add(statValue);
                }
            }

            //
            // Set up the statistic line series
            //
            NLineSeries line = new NLineSeries();
            chart.Series.Add(line);
            line.Name = "Statistic";
            line.UseXValues = true;
            line.InflateMargins = true;
            line.DataLabelStyle.Visible = false;
            line.BorderStyle = new NStrokeStyle(1.6f, Color.Tomato);

            // Set up the marker style for the regular points
            line.MarkerStyle.Visible = true;
            line.MarkerStyle.FillStyle = new NColorFillStyle(Color.SkyBlue);
            line.MarkerStyle.BorderStyle = new NStrokeStyle(1.0f, Color.Tomato);
            line.MarkerStyle.PointShape = PointShape.Sphere;
            line.MarkerStyle.Width = new NLength(4.0f);
            line.MarkerStyle.Height = new NLength(4.0f);

            // Add the statistic
            for (int i = 0; i < nppoints; i++)
            {
                line.XValues.Add(xstart + xincrement * i);

                double statValue = stats.Statistic[i];

                // Do not display a marker if the point is an outlier
                if ((statValue > stats.UCL[i]) || (statValue < stats.LCL[i]))
                {
                    NMarkerStyle outlierMarker = new NMarkerStyle();
                    outlierMarker.Visible = false;
                    line.MarkerStyles[i] = outlierMarker;
                }
            }

            line.Values.AddRange(stats.Statistic.DataBlock.Data);

            //
            // Set up the UCL and LCL lines
            //
            if (stats.ConstControlLimits)
            {
                bool showLCL = (stats.LCL.Length > 0);
                bool showUCL = (stats.UCL.Length > 0);

                if (showLCL)
                {
                    double lclValue = stats.LCL[0];

                    // Set up the LCL const line
                    NAxisConstLine lcl = new NAxisConstLine();
                    lcl.StrokeStyle = new NStrokeStyle(1.0f, Color.Gray, LinePattern.Dash);
                    lcl.Value = lclValue;
                    lcl.ShowAtWalls = new ChartWallType[] { ChartWallType.Back };
                    chart.Axis(StandardAxis.PrimaryY).ConstLines.Add(lcl);

                    // Show LCL label
                    SetValueLabel(chart, lclValue, "LCL", true);
                }

                if (showUCL)
                {
                    double uclValue = stats.UCL[0];

                    // Set up the UCL const line
                    NAxisConstLine ucl = new NAxisConstLine();
                    ucl.Value = uclValue;
                    ucl.StrokeStyle = new NStrokeStyle(1.0f, Color.Gray, LinePattern.Dash);
                    ucl.ShowAtWalls = new ChartWallType[] { ChartWallType.Back };
                    chart.Axis(StandardAxis.PrimaryY).ConstLines.Add(ucl);

                    // Show UCL label
                    SetValueLabel(chart, uclValue, "UCL", true);
                }

                // Ensure that the UCL and LCL values are visible
                NRange1DD clRange = new NRange1DD();

                if (showLCL && showUCL)
                {
                    clRange.Begin = stats.LCL[0];
                    clRange.End = stats.UCL[0];
                }
                else if (showLCL)
                {
                    clRange.End = clRange.Begin = stats.LCL[0];
                }
                else if (showUCL)
                {
                    clRange.End = clRange.Begin = stats.UCL[0];
                }

                clRange.Inflate(0.5);

                chart.Axis(StandardAxis.PrimaryY).UpdateScale();
                chart.Axis(StandardAxis.PrimaryY).SynchronizeScaleWithConfigurator = false;

                // custom tick inflator
                NCustomRangeInflator inflator = new NCustomRangeInflator(new NRange1DD[] { clRange });
                inflator.InflateBegin = true;
                inflator.InflateEnd = true;
                chart.Axis(StandardAxis.PrimaryY).Scale.ContentRangeInflators.Add(inflator);
            }
            else
            {
                // Set up the UCL line series
                AddStepLineSeries(chart, "UCL", stats.UCL, xstart, xincrement);

                // Set up the LCL line series
                AddStepLineSeries(chart, "LCL", stats.LCL, xstart, xincrement);

                // Show UCL label
                if (stats.UCL.Length > 0)
                {
                    int lastIndexUCL = stats.UCL.Length - 1;
                    SetValueLabel(chart, stats.UCL[lastIndexUCL], "UCL", false);
                }

                // Show LCL label
                if (stats.LCL.Length > 0)
                {
                    int lastIndexLCL = stats.LCL.Length - 1;
                    SetValueLabel(chart, stats.LCL[lastIndexLCL], "LCL", false);
                }
            }

            //
            // Set up the center line
            //
            NAxisConstLine cl1 = new NAxisConstLine();
            cl1.StrokeStyle = new NStrokeStyle(1.0f, Color.DodgerBlue, LinePattern.Dot);
            cl1.Value = stats.CenterLine;
            cl1.ShowAtWalls = new ChartWallType[] { ChartWallType.Back };
            chart.Axis(StandardAxis.PrimaryY).ConstLines.Add(cl1);

            // Show CL label
            SetValueLabel(chart, stats.CenterLine, "CL", true);
        }
        private void ApplyScaleSectionToAxis(NLinearScaleConfigurator scale, string text, NRange1DD range, Color color)
        {
            NScaleSectionStyle scaleSection = new NScaleSectionStyle();

            scaleSection.Range                    = range;
            scaleSection.LabelTextStyle           = new NTextStyle();
            scaleSection.LabelTextStyle.FillStyle = new NColorFillStyle(color);
            scaleSection.LabelTextStyle.FontStyle = new NFontStyle("Arial", 10, FontStyle.Bold | FontStyle.Italic);
            scaleSection.MajorTickStrokeStyle     = new NStrokeStyle(color);

            scale.Sections.Add(scaleSection);

            NCustomRangeLabel rangeLabel = new NCustomRangeLabel(range, text);

            rangeLabel.Style.WrapText            = false;
            rangeLabel.Style.KeepInsideRuler     = false;
            rangeLabel.Style.StrokeStyle.Color   = color;
            rangeLabel.Style.TextStyle.FillStyle = new NColorFillStyle(Color.White);
            rangeLabel.Style.Angle    = new NScaleLabelAngle(ScaleLabelAngleMode.Scale, 0);
            rangeLabel.Style.TickMode = RangeLabelTickMode.Center;
            scale.CustomLabels.Add(rangeLabel);
        }
Ejemplo n.º 4
0
        internal void GenerateData(NXYScatterSeries xyScatterSeries, double value, int nCount, NRange1DD range)
        {
            xyScatterSeries.ClearDataPoints();
            DateTime dt = new DateTime(2009, 1, 5);

            for (int nIndex = 0; nIndex < nCount; nIndex++)
            {
                bool upward = false;

                if (range.Begin > value)
                {
                    upward = true;
                }
                else if (range.End < value)
                {
                    upward = false;
                }
                else
                {
                    upward = Random.NextDouble() > 0.5;
                }

                xyScatterSeries.Values.Add(value);

                if (upward)
                {
                    value += (2 + (Random.NextDouble() * 20));
                }
                else
                {
                    value -= (2 + (Random.NextDouble() * 20));
                }

                while (true)
                {
                    dt = dt.AddDays(1);

                    if (dt.DayOfWeek != DayOfWeek.Saturday && dt.DayOfWeek != DayOfWeek.Sunday)
                    {
                        xyScatterSeries.XValues.Add(dt.ToOADate());
                        break;
                    }
                }
            }
        }
        protected void Page_Load(object sender, System.EventArgs e)
        {
            nChartControl1.BackgroundStyle.FrameStyle.Visible = false;
            nChartControl1.Panels.Clear();

            // set a chart title
            NLabel header = new NLabel("Linear Gauge Indicators");

            header.TextStyle.FontStyle        = new NFontStyle("Times New Roman", 14, FontStyle.Italic);
            header.TextStyle.ShadowStyle.Type = ShadowType.LinearBlur;
            header.ContentAlignment           = ContentAlignment.BottomRight;
            header.Location = new NPointL(new NLength(3, NRelativeUnit.ParentPercentage),
                                          new NLength(2, NRelativeUnit.ParentPercentage));
            nChartControl1.Panels.Add(header);

            // create a linear gauge
            m_LinearGauge = new NLinearGaugePanel();
            nChartControl1.Panels.Add(m_LinearGauge);
            m_LinearGauge.ContentAlignment    = ContentAlignment.MiddleCenter;
            m_LinearGauge.BorderStyle         = new NEdgeBorderStyle(BorderShape.RoundedRect);
            m_LinearGauge.PaintEffect         = new NGelEffectStyle();
            m_LinearGauge.BackgroundFillStyle = new NGradientFillStyle(Color.Gray, Color.Black);

            m_LinearGauge.Axes.Clear();

            NRange1DD celsiusRange = new NRange1DD(-40, 60);

            // add celsius and farenheit axes
            NGaugeAxis celsiusAxis = new NGaugeAxis();

            celsiusAxis.Range  = celsiusRange;
            celsiusAxis.Anchor = new NModelGaugeAxisAnchor(new NLength(-5), VertAlign.Center, RulerOrientation.Left, 0, 100);
            m_LinearGauge.Axes.Add(celsiusAxis);

            NGaugeAxis farenheitAxis = new NGaugeAxis();

            farenheitAxis.Range  = new NRange1DD(CelsiusToFarenheit(celsiusRange.Begin), CelsiusToFarenheit(celsiusRange.End));
            farenheitAxis.Anchor = new NModelGaugeAxisAnchor(new NLength(5), VertAlign.Center, RulerOrientation.Right, 0, 100);
            m_LinearGauge.Axes.Add(farenheitAxis);

            // configure the scales
            NLinearScaleConfigurator celsiusScale = (NLinearScaleConfigurator)celsiusAxis.ScaleConfigurator;

            ConfigureScale(celsiusScale, "°C");
            celsiusScale.Sections.Add(CreateSection(Color.Red, Color.Red, new NRange1DD(40, 60)));
            celsiusScale.Sections.Add(CreateSection(Color.Blue, Color.SkyBlue, new NRange1DD(-40, -20)));

            NLinearScaleConfigurator farenheitScale = (NLinearScaleConfigurator)farenheitAxis.ScaleConfigurator;

            ConfigureScale(farenheitScale, "°F");

            farenheitScale.Sections.Add(CreateSection(Color.Red, Color.Red, new NRange1DD(CelsiusToFarenheit(40), CelsiusToFarenheit(60))));
            farenheitScale.Sections.Add(CreateSection(Color.Blue, Color.SkyBlue, new NRange1DD(CelsiusToFarenheit(-40), CelsiusToFarenheit(-20))));

            // now add two indicators
            m_Indicator1                   = new NRangeIndicator();
            m_Indicator1.Value             = 10;
            m_Indicator1.StrokeStyle.Color = Color.DarkBlue;
            m_Indicator1.FillStyle         = new NGradientFillStyle(GradientStyle.Vertical, GradientVariant.Variant1, Color.LightBlue, Color.Blue);
            m_LinearGauge.Indicators.Add(m_Indicator1);

            m_Indicator2                         = new NMarkerValueIndicator();
            m_Indicator2.Value                   = 33;
            m_Indicator2.Shape.FillStyle         = new NGradientFillStyle(GradientStyle.Horizontal, GradientVariant.Variant1, Color.White, Color.Red);
            m_Indicator2.Shape.StrokeStyle.Color = Color.DarkRed;
            m_LinearGauge.Indicators.Add(m_Indicator2);

            // init form controls
            if (!Page.IsPostBack)
            {
                WebExamplesUtilities.FillComboWithEnumValues(RangeIndicatorOriginModeDropDownList, typeof(OriginMode));
                RangeIndicatorOriginModeDropDownList.SelectedIndex = 0;

                WebExamplesUtilities.FillComboWithEnumValues(ValueIndicatorShapeDropDownList, typeof(SmartShape2D));
                ValueIndicatorShapeDropDownList.SelectedIndex = (int)SmartShape2D.Triangle;

                WebExamplesUtilities.FillComboWithEnumValues(GaugeOrientationDropDownList, typeof(LinearGaugeOrientation));
                GaugeOrientationDropDownList.SelectedIndex = 0;

                WebExamplesUtilities.FillComboWithValues(ValueIndicatorDropDownList, -20, 60, 10);
                WebExamplesUtilities.FillComboWithValues(RangeIndicatorValueDropDownList, -20, 60, 10);
                WebExamplesUtilities.FillComboWithValues(RangeIndicatorOriginDropDownList, -20, 60, 10);
                RangeIndicatorOriginDropDownList.SelectedIndex = 5;

                RangeIndicatorValueDropDownList.SelectedValue = m_Indicator1.Value.ToString();
                ValueIndicatorDropDownList.SelectedValue      = m_Indicator2.Value.ToString();
            }

            m_LinearGauge.Orientation = (LinearGaugeOrientation)GaugeOrientationDropDownList.SelectedIndex;

            if (m_LinearGauge.Orientation == LinearGaugeOrientation.Horizontal)
            {
                m_LinearGauge.Location = new NPointL(new NLength(50, NRelativeUnit.ParentPercentage), new NLength(50, NRelativeUnit.ParentPercentage));
                m_LinearGauge.Size     = new NSizeL(new NLength(90, NRelativeUnit.ParentPercentage), new NLength(55, NRelativeUnit.ParentPercentage));
            }
            else
            {
                m_LinearGauge.Location = new NPointL(new NLength(50, NRelativeUnit.ParentPercentage), new NLength(54, NRelativeUnit.ParentPercentage));
                m_LinearGauge.Size     = new NSizeL(new NLength(37, NRelativeUnit.ParentPercentage), new NLength(85, NRelativeUnit.ParentPercentage));
            }
            m_Indicator1.OriginMode = (OriginMode)RangeIndicatorOriginModeDropDownList.SelectedIndex;
            m_Indicator1.Origin     = Convert.ToDouble(RangeIndicatorOriginDropDownList.SelectedValue);
            m_Indicator1.Value      = Convert.ToDouble(RangeIndicatorValueDropDownList.SelectedValue);

            N2DSmartShapeFactory factory = new N2DSmartShapeFactory(m_Indicator2.Shape.FillStyle, m_Indicator2.Shape.StrokeStyle, m_Indicator2.Shape.ShadowStyle);

            m_Indicator2.Shape = factory.CreateShape((SmartShape2D)ValueIndicatorShapeDropDownList.SelectedIndex);
            m_Indicator2.Value = Convert.ToDouble(ValueIndicatorDropDownList.SelectedValue);

            if (m_Indicator1.OriginMode != OriginMode.Custom)
            {
                RangeIndicatorOriginDropDownList.Enabled = false;
            }
            else
            {
                RangeIndicatorOriginDropDownList.Enabled = true;
            }
        }
Ejemplo n.º 6
0
        internal void GenerateOHLCData(NStockSeries s, double dPrevClose, int nCount, NRange1DD range)
        {
            double open, high, low, close;

            s.ClearDataPoints();

            for (int nIndex = 0; nIndex < nCount; nIndex++)
            {
                open = dPrevClose;
                bool upward = false;

                if (range.Begin > dPrevClose)
                {
                    upward = true;
                }
                else if (range.End < dPrevClose)
                {
                    upward = false;
                }
                else
                {
                    upward = Random.NextDouble() > 0.5;
                }

                if (upward)
                {
                    // upward price change
                    close = open + (2 + (Random.NextDouble() * 20));
                    high  = close + (Random.NextDouble() * 10);
                    low   = open - (Random.NextDouble() * 10);
                }
                else
                {
                    // downward price change
                    close = open - (2 + (Random.NextDouble() * 20));
                    high  = open + (Random.NextDouble() * 10);
                    low   = close - (Random.NextDouble() * 10);
                }

                if (low < 1)
                {
                    low = 1;
                }

                dPrevClose = close;

                s.OpenValues.Add(open);
                s.HighValues.Add(high);
                s.LowValues.Add(low);
                s.CloseValues.Add(close);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Called to initialize the example
        /// </summary>
        /// <param name="chartControl"></param>
        public override void Create()
        {
            // set a chart title
            NLabel title = nChartControl1.Labels.AddHeader("Bar Palette");

            title.TextStyle.FontStyle = new NFontStyle("Times New Roman", 18, System.Drawing.FontStyle.Italic);

            // configure the chart
            m_Chart = nChartControl1.Charts[0];
            m_Chart.Projection.SetPredefinedProjection(PredefinedProjection.OrthogonalHalf);
            m_Chart.Axis(StandardAxis.Depth).Visible = false;

            // add interlace stripe
            NAxis yAxis = m_Chart.Axis(StandardAxis.PrimaryY);
            NLinearScaleConfigurator linearScale = yAxis.ScaleConfigurator as NLinearScaleConfigurator;
            NScaleStripStyle         strip       = new NScaleStripStyle(new NColorFillStyle(Color.Beige), null, true, 0, 0, 1, 1);

            strip.Interlaced = true;
            //linearScale.Strips.Add(strip);

            // setup a bar series
            m_Bar                        = new NBarSeries();
            m_Bar.Name                   = "Bar Series";
            m_Bar.InflateMargins         = true;
            m_Bar.UseXValues             = false;
            m_Bar.DataLabelStyle.Visible = false;

            NPalette palette = new NPalette();

            palette.SmoothPalette = true;
            palette.Clear();
            palette.Add(0, Color.Green);
            palette.Add(60, Color.Yellow);
            palette.Add(120, Color.Red);

            m_Bar.Palette = palette;

            m_AxisRange = new NRange1DD(0, 130);

            // limit the axis range to 0, 130
            yAxis.View = new NRangeAxisView(m_AxisRange, true, true);
            m_Chart.Series.Add(m_Bar);

            int indicatorCount = 10;

            m_IndicatorPhase = new double[indicatorCount];

            // add some data to the bar series
            for (int i = 0; i < indicatorCount; i++)
            {
                m_IndicatorPhase[i] = i * 30;
                m_Bar.Values.Add(0);
            }

            NExampleHelpers.FillComboWithEnumValues(BarPaletteModeComboBox, typeof(PaletteColorMode));
            BarPaletteModeComboBox.SelectedIndex = (int)PaletteColorMode.Spread;
            SmoothPaletteCheckBox.IsChecked      = true;

            m_Timer          = new System.Windows.Threading.DispatcherTimer();
            m_Timer.Tick    += new EventHandler(OnTimerTick);
            m_Timer.Interval = new TimeSpan(0, 0, 0, 0, 50);
            m_Timer.Start();
        }
Ejemplo n.º 8
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);
        }
        public static void GenerateOHLCData(NStockSeries s, double dPrevClose, int nCount, NRange1DD range)
        {
            double open, high, low, close;

            s.ClearDataPoints();

            for (int nIndex = 0; nIndex < nCount; nIndex++)
            {
                GenerateOHLCDataPoint(dPrevClose, range, out open, out high, out low, out close);

                dPrevClose = close;

                s.OpenValues.Add(open);
                s.HighValues.Add(high);
                s.LowValues.Add(low);
                s.CloseValues.Add(close);
            }
        }
        public override void Initialize()
        {
            base.Initialize();

            // Enable GPU acceleration
            nChartControl1.Settings.RenderSurface = RenderSurface.Window;

            nChartControl1.Panels.Clear();

            // set a chart title
            NLabel title = new NLabel("Grid Surface Cross Section");

            title.TextStyle.FontStyle = new NFontStyle("Times New Roman", 18, FontStyle.Italic);
            title.TextStyle.FillStyle = new NColorFillStyle(GreyBlue);
            title.DockMode            = PanelDockMode.Top;
            title.Margins             = new NMarginsL(10);
            nChartControl1.Panels.Add(title);

            NDockPanel containerPanel = new NDockPanel();

            containerPanel.PositionChildPanelsInContentBounds = true;
            containerPanel.Margins  = new NMarginsL(10, 0, 10, 10);
            containerPanel.DockMode = PanelDockMode.Fill;
            nChartControl1.Panels.Add(containerPanel);

            // configure the chart
            NCartesianChart surfaceChart = new NCartesianChart();

            containerPanel.ChildPanels.Add(surfaceChart);
            surfaceChart.DockMode   = PanelDockMode.Top;
            surfaceChart.Size       = new NSizeL(new NLength(0.0f), new NLength(70.0f, NRelativeUnit.ParentPercentage));
            surfaceChart.Enable3D   = true;
            surfaceChart.Width      = 60.0f;
            surfaceChart.Depth      = 60.0f;
            surfaceChart.Height     = 15.0f;
            surfaceChart.BoundsMode = BoundsMode.Fit;
            surfaceChart.Projection.SetPredefinedProjection(PredefinedProjection.PerspectiveTilted);
            surfaceChart.Projection.Elevation = 22;
            surfaceChart.Projection.Rotation  = -68;
            surfaceChart.LightModel.SetPredefinedLightModel(PredefinedLightModel.ShinyTopLeft);

            // setup axes
            NOrdinalScaleConfigurator ordinalScale = (NOrdinalScaleConfigurator)surfaceChart.Axis(StandardAxis.PrimaryX).ScaleConfigurator;

            ordinalScale.MajorGridStyle.SetShowAtWall(ChartWallType.Floor, true);
            ordinalScale.MajorGridStyle.SetShowAtWall(ChartWallType.Back, true);
            ordinalScale.DisplayDataPointsBetweenTicks = false;

            ordinalScale = (NOrdinalScaleConfigurator)surfaceChart.Axis(StandardAxis.Depth).ScaleConfigurator;
            ordinalScale.MajorGridStyle.SetShowAtWall(ChartWallType.Floor, true);
            ordinalScale.MajorGridStyle.SetShowAtWall(ChartWallType.Left, true);
            ordinalScale.DisplayDataPointsBetweenTicks = false;

            // add the surface series
            m_SurfaceSeries = new NGridSurfaceSeries();
            surfaceChart.Series.Add(m_SurfaceSeries);
            m_SurfaceSeries.Name          = "Surface";
            m_SurfaceSeries.Legend.Mode   = SeriesLegendMode.SeriesLogic;
            m_SurfaceSeries.PositionValue = 10.0;
            m_SurfaceSeries.Data.SetGridSize(1000, 1000);
            m_SurfaceSeries.SyncPaletteWithAxisScale       = false;
            m_SurfaceSeries.PaletteSteps                   = 8;
            m_SurfaceSeries.ValueFormatter.FormatSpecifier = "0.00";
            m_SurfaceSeries.FillStyle   = new NColorFillStyle(Color.YellowGreen);
            m_SurfaceSeries.ShadingMode = ShadingMode.Smooth;
            m_SurfaceSeries.FrameMode   = SurfaceFrameMode.None;
            m_SurfaceSeries.FillMode    = SurfaceFillMode.ZoneTexture;

            // add the cross section line series
            m_CrossSection3DSeries = new NPointSeries();
            surfaceChart.Series.Add(m_CrossSection3DSeries);
            m_CrossSection3DSeries.Size                   = new NLength(10);
            m_CrossSection3DSeries.PointShape             = PointShape.Sphere;
            m_CrossSection3DSeries.FillStyle              = new NColorFillStyle(Color.Red);
            m_CrossSection3DSeries.DataLabelStyle.Visible = false;
            m_CrossSection3DSeries.UseXValues             = true;
            m_CrossSection3DSeries.UseZValues             = true;

            FillData(m_SurfaceSeries);

            NCartesianChart crossSectionChart = new NCartesianChart();

            crossSectionChart.BoundsMode = BoundsMode.Stretch;
            crossSectionChart.DockMode   = PanelDockMode.Fill;
            crossSectionChart.Margins    = new NMarginsL(0, 10, 0, 0);

            crossSectionChart.Axis(StandardAxis.PrimaryX).ScaleConfigurator            = new NLinearScaleConfigurator();
            crossSectionChart.Axis(StandardAxis.PrimaryX).ScaleConfigurator.Title.Text = "Distance";
            crossSectionChart.Axis(StandardAxis.PrimaryY).ScaleConfigurator.Title.Text = "Value";

            m_CrossSection2DSeries = new NLineSeries();
            m_CrossSection2DSeries.DataLabelStyle.Visible = false;
            m_CrossSection2DSeries.UseXValues             = true;
            crossSectionChart.Series.Add(m_CrossSection2DSeries);

            containerPanel.ChildPanels.Add(crossSectionChart);

            nChartControl1.View.RecalcLayout();

            NRange1DD xAxisRange = surfaceChart.Axis(StandardAxis.PrimaryX).Scale.RulerRange;
            NRange1DD yAxisRange = surfaceChart.Axis(StandardAxis.PrimaryY).Scale.RulerRange;
            NRange1DD zAxisRange = surfaceChart.Axis(StandardAxis.Depth).Scale.RulerRange;

            m_DragPlane = new NDragPlane(
                new NVector3DD(0, yAxisRange.End, 0),
                new NVector3DD(xAxisRange.End, yAxisRange.End, zAxisRange.End),
                new NVector3DD(xAxisRange.End, 0, zAxisRange.End),
                new NVector3DD(0, 0, 0)
                );

            m_DragPlane.DragPlaneChanged += new EventHandler(OnDragPlaneChanged);
            m_DragPlaneTool = new NDragPlaneTool(m_DragPlane);
            m_DragPlane.AddToChart(surfaceChart);

            nChartControl1.Controller.Tools.Add(new NPanelSelectorTool());
            nChartControl1.Controller.Tools.Add(m_DragPlaneTool);
            nChartControl1.Controller.Tools.Add(new NTrackballTool());

            // enable fixed axis ranges
            surfaceChart.Axis(StandardAxis.PrimaryX).View = new NRangeAxisView(xAxisRange, true, true);
            surfaceChart.Axis(StandardAxis.PrimaryY).View = new NRangeAxisView(yAxisRange, true, true);
            surfaceChart.Axis(StandardAxis.Depth).View    = new NRangeAxisView(zAxisRange, true, true);

            // turn off plot box clipping
            surfaceChart.Axis(StandardAxis.PrimaryX).ClipMode = AxisClipMode.Never;
            surfaceChart.Axis(StandardAxis.PrimaryY).ClipMode = AxisClipMode.Never;
            surfaceChart.Axis(StandardAxis.Depth).ClipMode    = AxisClipMode.Never;

            DragPlaneComboBox.Items.Add("XY");
            DragPlaneComboBox.Items.Add("XZ");
            DragPlaneComboBox.Items.Add("ZY");
            DragPlaneComboBox.SelectedIndex = 1;

            // update the cross section
            OnDragPlaneChanged(null, null);
        }
Ejemplo n.º 11
0
 public NRangeAxisView(NRange1DD nRange1DD, bool v1, bool v2)
 {
     this.nRange1DD = nRange1DD;
     this.v1        = v1;
     this.v2        = v2;
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="xRange"></param>
        /// <param name="yRange"></param>
        /// <returns></returns>
        private static string FormatLabel(NRange1DD xRange, NRange1DD yRange)
        {
            string valueFormat = "0.00";

            return("Data Pan Tool <br/><font size='12pt'>XRange[" + xRange.Begin.ToString(valueFormat) + ", " + xRange.End.ToString(valueFormat) + "], YRange[" + yRange.Begin.ToString(valueFormat) + ", " + yRange.End.ToString(valueFormat) + "]</font>");
        }
        public override void Create()
        {
            nChartControl1.Panels.Clear();

            // set a chart title
            NLabel header = new NLabel("Linear Gauge Indicators");

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

            nChartControl1.Panels.Add(header);

            // create a linear gauge
            m_LinearGauge = new NLinearGaugePanel();
            nChartControl1.Panels.Add(m_LinearGauge);
            m_LinearGauge.ContentAlignment    = System.Drawing.ContentAlignment.MiddleCenter;
            m_LinearGauge.Location            = new NPointL(new NLength(50, NRelativeUnit.ParentPercentage), new NLength(50, NRelativeUnit.ParentPercentage));
            m_LinearGauge.PaintEffect         = new NGelEffectStyle();
            m_LinearGauge.BorderStyle         = new NEdgeBorderStyle(BorderShape.RoundedRect);
            m_LinearGauge.BackgroundFillStyle = new NGradientFillStyle(System.Drawing.Color.Gray, System.Drawing.Color.Black);

            m_LinearGauge.Axes.Clear();

            NRange1DD celsiusRange = new NRange1DD(-40, 60);

            // add celsius and farenheit axes
            NGaugeAxis celsiusAxis = new NGaugeAxis();

            celsiusAxis.Range  = celsiusRange;
            celsiusAxis.Anchor = new NModelGaugeAxisAnchor(new NLength(-5), VertAlign.Center, RulerOrientation.Left, 0, 100);
            m_LinearGauge.Axes.Add(celsiusAxis);

            NGaugeAxis farenheitAxis = new NGaugeAxis();

            farenheitAxis.Range  = new NRange1DD(CelsiusToFarenheit(celsiusRange.Begin), CelsiusToFarenheit(celsiusRange.End));
            farenheitAxis.Anchor = new NModelGaugeAxisAnchor(new NLength(5), VertAlign.Center, RulerOrientation.Right, 0, 100);
            m_LinearGauge.Axes.Add(farenheitAxis);

            // configure the scales
            NLinearScaleConfigurator celsiusScale = (NLinearScaleConfigurator)celsiusAxis.ScaleConfigurator;

            ConfigureScale(celsiusScale, "°C");
            celsiusScale.Sections.Add(CreateSection(System.Drawing.Color.Red, System.Drawing.Color.Red, new NRange1DD(40, 60)));
            celsiusScale.Sections.Add(CreateSection(System.Drawing.Color.Blue, System.Drawing.Color.SkyBlue, new NRange1DD(-40, -20)));

            NLinearScaleConfigurator farenheitScale = (NLinearScaleConfigurator)farenheitAxis.ScaleConfigurator;

            ConfigureScale(farenheitScale, "°F");

            farenheitScale.Sections.Add(CreateSection(System.Drawing.Color.Red, System.Drawing.Color.Red, new NRange1DD(CelsiusToFarenheit(40), CelsiusToFarenheit(60))));
            farenheitScale.Sections.Add(CreateSection(System.Drawing.Color.Blue, System.Drawing.Color.SkyBlue, new NRange1DD(CelsiusToFarenheit(-40), CelsiusToFarenheit(-20))));

            // now add two indicators
            m_Indicator1                   = new NRangeIndicator();
            m_Indicator1.Value             = 10;
            m_Indicator1.StrokeStyle.Color = System.Drawing.Color.DarkBlue;
            m_Indicator1.FillStyle         = new NGradientFillStyle(GradientStyle.Vertical, GradientVariant.Variant1, System.Drawing.Color.LightBlue, System.Drawing.Color.Blue);
            m_LinearGauge.Indicators.Add(m_Indicator1);

            m_Indicator2                         = new NMarkerValueIndicator();
            m_Indicator2.Value                   = 33;
            m_Indicator2.Shape.FillStyle         = new NGradientFillStyle(GradientStyle.Horizontal, GradientVariant.Variant1, System.Drawing.Color.White, System.Drawing.Color.Red);
            m_Indicator2.Shape.StrokeStyle.Color = System.Drawing.Color.DarkRed;
            m_LinearGauge.Indicators.Add(m_Indicator2);

            // init form controls

            NExampleHelpers.BindComboToItemSource(ValueIndicatorComboBox, -20, 60, 1);
            ValueIndicatorComboBox.SelectedItem = (int)m_Indicator2.Value;

            NExampleHelpers.BindComboToItemSource(RangeIndicatorValueComboBox, -20, 60, 1);
            RangeIndicatorValueComboBox.SelectedItem = (int)m_Indicator1.Value;

            NExampleHelpers.BindComboToItemSource(MarkerWidthComboBox, 1, 40, 1);
            MarkerWidthComboBox.SelectedItem = (int)m_Indicator2.Width.Value;

            NExampleHelpers.BindComboToItemSource(MarkerHeightComboBox, 1, 40, 1);
            MarkerHeightComboBox.SelectedItem = (int)m_Indicator2.Height.Value;

            NExampleHelpers.FillComboWithEnumValues(RangeIndicatorOriginModeComboBox, typeof(OriginMode));
            RangeIndicatorOriginModeComboBox.SelectedIndex = 0;

            NExampleHelpers.BindComboToItemSource(RangeIndicatorOriginComboBox, -20, 60, 1);
            RangeIndicatorOriginComboBox.SelectedItem = (int)m_Indicator1.Origin;

            NExampleHelpers.FillComboWithEnumValues(ValueIndicatorShapeComboBox, typeof(SmartShape2D));
            ValueIndicatorShapeComboBox.SelectedIndex = (int)SmartShape2D.Triangle;

            NExampleHelpers.FillComboWithEnumValues(GaugeOrientationCombo, typeof(LinearGaugeOrientation));
            GaugeOrientationCombo.SelectedIndex = 0;
        }
        private NScaleSectionStyle CreateSection(System.Drawing.Color tickColor, System.Drawing.Color labelColor, NRange1DD range)
        {
            NScaleSectionStyle scaleSection = new NScaleSectionStyle();

            scaleSection.Range              = range;
            scaleSection.LabelTextStyle     = new NTextStyle(new NFontStyle(), tickColor);
            scaleSection.MajorTickFillStyle = new NColorFillStyle(tickColor);

            NTextStyle labelStyle = new NTextStyle();

            labelStyle.FillStyle        = new NColorFillStyle(labelColor);
            labelStyle.FontStyle        = new NFontStyle("Arial", 12, System.Drawing.FontStyle.Bold);
            scaleSection.LabelTextStyle = labelStyle;

            return(scaleSection);
        }
        private void FillData()
        {
            if (nChartControl1 == null)
            {
                return;
            }

            NChart chart = nChartControl1.Charts[0];
            NTriangulatedSurfaceSeries surface     = (NTriangulatedSurfaceSeries)chart.Series[0];
            NTriangulatedSurfaceData   surfaceData = surface.Data;

            if (m_SurfaceVectorData == null)
            {
                Random rand = new Random();

                const int countX = 100;
                const int countZ = 100;

                NRange1DD rangeX = new NRange1DD(-10, 10);
                NRange1DD rangeZ = new NRange1DD(-10, 10);

                double stepX = rangeX.GetLength() / (countX - 1);
                double stepZ = rangeZ.GetLength() / (countZ - 1);

                double cx = -3.0;
                double cz = -5.0;

                NVector3DD[] vectorData = new NVector3DD[countZ * countX];
                int          index      = 0;

                for (int n = 0; n < countZ; n++)
                {
                    double z = rangeZ.Begin + n * stepZ;

                    for (int m = 0; m < countX; m++)
                    {
                        double x        = rangeX.Begin + m * stepX;
                        double dx       = cx - x;
                        double dz       = cz - z;
                        double distance = Math.Sqrt(dx * dx + dz * dz);

                        vectorData[index++] = new NVector3DD(x, Math.Sin(distance) * Math.Exp(-distance * 0.1), z);
                    }
                }

                m_SurfaceVectorData = vectorData;
            }

            NVector3DD[] newSurfaceVectorData = m_SurfaceVectorData;

            if (enableClusteringCheck.Checked)
            {
                NPointSetSimplifier3D simplifier = new NPointSetSimplifier3D();
                simplifier.DistanceFactor = (double)distanceFactorNumericUpDown.Value;

                newSurfaceVectorData = simplifier.Simplify(newSurfaceVectorData);
            }

            surfaceData.Clear();
            surfaceData.AddValues(newSurfaceVectorData);

            nChartControl1.Refresh();
        }