protected void Page_Load(object sender, System.EventArgs e) { nChartControl1.BackgroundStyle.FrameStyle.Visible = false; nChartControl1.Panels.Clear(); // set a chart title NLabel title = new NLabel("Data Distribution"); title.TextStyle.FontStyle = new NFontStyle("Times New Roman", 14, FontStyle.Italic); title.TextStyle.ShadowStyle.Type = ShadowType.LinearBlur; title.ContentAlignment = ContentAlignment.BottomCenter; title.Margins = new NMarginsL(5, 5, 5, 5); title.DockMode = PanelDockMode.Top; title.Location = new NPointL( new NLength(50, NRelativeUnit.ParentPercentage), new NLength(2, NRelativeUnit.ParentPercentage)); // no legend nChartControl1.Legends.Clear(); // create box and whiskers chart NChart boxChart = new NCartesianChart(); boxChart.Margins = new NMarginsL(5, 0, 5, 5); boxChart.BoundsMode = BoundsMode.Stretch; boxChart.DockMode = PanelDockMode.Right; boxChart.Size = new NSizeL(new NLength(20, NRelativeUnit.ParentPercentage), new NLength(100, NRelativeUnit.ParentPercentage)); // create point chart NChart pointChart = new NCartesianChart(); pointChart.Margins = new NMarginsL(5, 0, 0, 5); pointChart.BoundsMode = BoundsMode.Stretch; pointChart.DockMode = PanelDockMode.Fill; // create a guide line to align the chart bottoms NSideGuideline bottomChartGuideline = new NSideGuideline(PanelSide.Bottom); nChartControl1.Document.RootPanel.Guidelines.Add(bottomChartGuideline); bottomChartGuideline.Targets.Add(pointChart); bottomChartGuideline.Targets.Add(boxChart); // arrange panels nChartControl1.Panels.Add(title); nChartControl1.Panels.Add(boxChart); nChartControl1.Panels.Add(pointChart); SetupCharts(pointChart, boxChart); bool showAverage = ShowAverageCheckBox.Checked; bool showOutliers = ShowOutliersCheckBox.Checked; NPointSeries pointSeries = (NPointSeries)pointChart.Series[0]; NBoxAndWhiskersSeries boxSeries = (NBoxAndWhiskersSeries)boxChart.Series[0]; NBoxAndWhiskersDataPoint bwdp = new NBoxAndWhiskersDataPoint(pointSeries.Values, showAverage, showOutliers); boxSeries.ClearDataPoints(); boxSeries.AddDataPoint(bwdp); }
private void AddPointGroup(NPointSeries point, int count) { Random rand = new Random(); double[] xValues = new double[count]; double[] yValues = new double[count]; double centerX = rand.Next(20); double centerY = rand.Next(20); for (int i = 0; i < count; i++) { double u1 = rand.NextDouble(); double u2 = rand.NextDouble(); if (u1 == 0) { u1 += 0.0001; } if (u2 == 0) { u2 += 0.0001; } double z0 = Math.Sqrt(-2 * Math.Log(u1)) * Math.Cos(2 * Math.PI * u2); double z1 = Math.Sqrt(-2 * Math.Log(u1)) * Math.Sin(2 * Math.PI * u2); xValues[i] = centerX + z0; yValues[i] = centerY + z1; } point.XValues.AddRange(xValues); point.Values.AddRange(yValues); }
private void GenerateXYData(NPointSeries series) { Random rand = new Random(); for (int i = 0; i < 200; i++) { double u1 = rand.NextDouble(); double u2 = rand.NextDouble(); if (u1 == 0) { u1 += 0.0001; } if (u2 == 0) { u2 += 0.0001; } double z0 = 100 * Math.Sqrt(-2 * Math.Log(u1)) * Math.Cos(2 * Math.PI * u2); double z1 = 100 * Math.Sqrt(-2 * Math.Log(u1)) * Math.Sin(2 * Math.PI * u2); series.XValues.Add(z0); series.Values.Add(z1); series.InteractivityStyles.Add(i, new NInteractivityStyle("X: " + z0.ToString("0.00") + ", Y:" + z1.ToString("0.00"))); } }
/// <summary> /// Gets the data point from the specified point /// </summary> /// <param name="point"></param> /// <returns></returns> protected int GetDataPointIndexFromPoint(NPoint point) { NPointSeries pointSeries = m_DragPlane.PointSeries; NChart chart = pointSeries.Chart; NModel3DToViewTransformation model3DToViewTransformation = new NModel3DToViewTransformation(GetView().Context, chart.Projection); float xHotSpotArea = 10; float yHotSpotArea = 10; int dataPointIndex = -1; for (int i = 0; i < pointSeries.Values.Count; i++) { double x = (double)pointSeries.XValues[i]; double y = (double)pointSeries.Values[i]; double z = (double)pointSeries.ZValues[i]; NVector3DF vecModelPoint; vecModelPoint.X = chart.Axis(StandardAxis.PrimaryX).TransformScaleToModel(false, x); vecModelPoint.Y = chart.Axis(StandardAxis.PrimaryY).TransformScaleToModel(false, y); vecModelPoint.Z = chart.Axis(StandardAxis.Depth).TransformScaleToModel(false, z); NPointF viewPoint = NPointF.Empty; model3DToViewTransformation.Transform(vecModelPoint, ref viewPoint); if (Math.Abs(viewPoint.X - point.X) < xHotSpotArea && Math.Abs(viewPoint.Y - point.Y) < yHotSpotArea) { dataPointIndex = i; break; } } return(dataPointIndex); }
private void GenerateXYData(NPointSeries series) { for (int i = 0; i < 200; i++) { double u1 = Random.NextDouble(); double u2 = Random.NextDouble(); if (u1 == 0) { u1 += 0.0001; } if (u2 == 0) { u2 += 0.0001; } double z0 = Math.Sqrt(-2 * Math.Log(u1)) * Math.Cos(2 * Math.PI * u2); double z1 = Math.Sqrt(-2 * Math.Log(u1)) * Math.Sin(2 * Math.PI * u2); series.XValues.Add(z0); series.Values.Add(z1); NInteractivityStyle interactivity = new NInteractivityStyle("X: " + z0.ToString("0.00") + ", Y:" + z1.ToString("0.00"), CursorType.Hand); series.InteractivityStyles.Add(i, interactivity); } }
private void NewDataButton_Click(object sender, System.EventArgs e) { NPointSeries point = (NPointSeries)nChartControl1.Charts[0].Series[0]; GenerateXYData(point); nChartControl1.Refresh(); }
public override void Initialize() { base.Initialize(); // set a chart title NLabel title = nChartControl1.Labels.AddHeader("Overlay Painting <br /><font size = '12pt'>(Move the mouse over the chart and press the mouse buttons.)</font>"); title.TextStyle.FontStyle = new NFontStyle("Times New Roman", 18, FontStyle.Italic); title.TextStyle.TextFormat = TextFormat.XML; // no legend nChartControl1.Legends.Clear(); // configure the chart NChart chart = nChartControl1.Charts[0]; chart.OverlayPaintCallback = this; // setup X axis NLinearScaleConfigurator scaleX = new NLinearScaleConfigurator(); scaleX.MajorGridStyle.ShowAtWalls = new ChartWallType[] { ChartWallType.Back }; scaleX.MajorGridStyle.LineStyle.Pattern = LinePattern.Dot; scaleX.RoundToTickMin = true; scaleX.RoundToTickMax = true; chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = scaleX; // setup Y axis NLinearScaleConfigurator scaleY = new NLinearScaleConfigurator(); scaleY.MajorGridStyle.ShowAtWalls = new ChartWallType[] { ChartWallType.Back }; scaleY.MajorGridStyle.LineStyle.Pattern = LinePattern.Dot; scaleY.RoundToTickMin = true; scaleY.RoundToTickMax = true; chart.Axis(StandardAxis.PrimaryY).ScaleConfigurator = scaleY; // add a point series NPointSeries point = (NPointSeries)chart.Series.Add(SeriesType.Point); point.Name = "Point Series"; point.DataLabelStyle.Visible = false; point.FillStyle = new NColorFillStyle(Color.FromArgb(160, LightOrange)); point.BorderStyle.Width = new NLength(0); point.Size = new NLength(1, NRelativeUnit.ParentPercentage); point.PointShape = PointShape.Ellipse; point.InflateMargins = true; point.UseXValues = true; GenerateXYData(point); // apply layout ConfigureStandardLayout(chart, title, null); // attach mouse move handler nChartControl1.MouseMove += new MouseEventHandler(nChartControl1_MouseMove); // start the timer m_Timer.Start(); }
public override void Initialize() { base.Initialize(); // set a chart title NLabel title = new NLabel("Step Line Intersections"); title.TextStyle.FontStyle = new NFontStyle("Times New Roman", 18, FontStyle.Italic); // no legend nChartControl1.Legends.Clear(); // configure the chart NChart chart = nChartControl1.Charts[0]; NLinearScaleConfigurator linearScale = chart.Axis(StandardAxis.PrimaryY).ScaleConfigurator as NLinearScaleConfigurator; // add interlace stripe NScaleStripStyle stripStyle = new NScaleStripStyle(new NColorFillStyle(Color.Beige), null, true, 0, 0, 1, 1); stripStyle.Interlaced = true; stripStyle.SetShowAtWall(ChartWallType.Back, true); stripStyle.SetShowAtWall(ChartWallType.Left, true); linearScale.StripStyles.Add(stripStyle); m_Line = (NStepLineSeries)chart.Series.Add(SeriesType.StepLine); m_Line.Name = "Series 1"; m_Line.DepthPercent = 50; m_Line.LineSize = 2; m_Line.DataLabelStyle.Visible = false; m_Line.MarkerStyle.Visible = false; m_Line.Values.FillRandom(Random, 12); m_Point = (NPointSeries)chart.Series.Add(SeriesType.Point); m_Point.UseXValues = true; m_Point.DataLabelStyle.Visible = false; m_Point.Size = new NLength(6); m_XCursor = new NAxisCursor(); m_XCursor.BeginEndAxis = (int)StandardAxis.PrimaryY; m_YCursor = new NAxisCursor(); m_YCursor.BeginEndAxis = (int)StandardAxis.PrimaryX; chart.Axis(StandardAxis.PrimaryX).Cursors.Add(m_XCursor); chart.Axis(StandardAxis.PrimaryY).Cursors.Add(m_YCursor); // apply layout ConfigureStandardLayout(chart, title, null); // apply style sheet NStyleSheet styleSheet = NStyleSheet.CreatePredefinedStyleSheet(PredefinedStyleSheet.Fresh); styleSheet.Apply(nChartControl1.Document); LineSegmentRouteCombo.FillFromEnum(typeof(LineSegmentRoute)); LineSegmentRouteCombo.SelectedIndex = 1; nChartControl1.MouseMove += new MouseEventHandler(OnChartControl1MouseMove); }
public override void Initialize() { base.Initialize(); // set a chart title NLabel title = nChartControl1.Labels.AddHeader("2D Point Chart Droplines"); title.TextStyle.FontStyle = new NFontStyle("Times New Roman", 18, FontStyle.Italic); // setup chart NChart chart = nChartControl1.Charts[0]; chart.Enable3D = true; chart.Width = chart.Height = chart.Depth = 50; chart.Axis(StandardAxis.Depth).Visible = true; chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = new NLinearScaleConfigurator(); chart.Axis(StandardAxis.Depth).ScaleConfigurator = new NLinearScaleConfigurator(); // add interlace stripe NLinearScaleConfigurator linearScale = chart.Axis(StandardAxis.PrimaryY).ScaleConfigurator as NLinearScaleConfigurator; NScaleStripStyle stripStyle = new NScaleStripStyle(new NColorFillStyle(Color.Beige), null, true, 0, 0, 1, 1); stripStyle.Interlaced = true; stripStyle.SetShowAtWall(ChartWallType.Back, true); stripStyle.SetShowAtWall(ChartWallType.Left, true); linearScale.StripStyles.Add(stripStyle); // setup point series m_Point = (NPointSeries)chart.Series.Add(SeriesType.Point); m_Point.Name = "Point Series"; m_Point.InflateMargins = true; m_Point.UseXValues = true; m_Point.UseZValues = true; m_Point.Size = new NLength(10, NGraphicsUnit.Point); m_Point.DataLabelStyle.Visible = false; Random random = new Random(); for (int i = 0; i < 100; i += 5) { m_Point.Values.Add(random.Next(200) - 100); m_Point.XValues.Add(random.Next(200) - 100); m_Point.ZValues.Add(random.Next(200) - 100); } // apply layout ConfigureStandardLayout(chart, title, nChartControl1.Legends[0]); // apply interactivity nChartControl1.Controller.Tools.Add(new NPanelSelectorTool()); nChartControl1.Controller.Tools.Add(new NTrackballTool()); // init form controls ShowVerticalDropLinesCheckBox.Checked = true; ShowHorizontalDropLinesCheckBox.Checked = true; ShowDepthDropLinesCheckBox.Checked = true; }
/// <summary> /// /// </summary> /// <returns></returns> protected override NWidget CreateExampleContent() { NChartView chartView = CreateCartesianChartView(); // configure title chartView.Surface.Titles[0].Text = "Custom Scale Breaks"; // configure chart m_Chart = (NCartesianChart)chartView.Surface.Charts[0]; // configure axes m_Chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XYLinear); Random random = new Random(); // create three random point series for (int i = 0; i < 3; i++) { NPointSeries point = new NPointSeries(); point.UseXValues = true; point.DataLabelStyle = new NDataLabelStyle(false); point.Size = 5; // fill in some random data for (int j = 0; j < 30; j++) { point.DataPoints.Add(new NPointDataPoint(5 + random.Next(90), 5 + random.Next(90))); } m_Chart.Series.Add(point); } // create scale breaks NScale xScale = m_Chart.Axes[ENCartesianAxis.PrimaryX].Scale; m_FirstHorzScaleBreak = CreateCustomScaleBreak(NColor.Orange, new NRange(10, 20)); xScale.ScaleBreaks.Add(m_FirstHorzScaleBreak); m_SecondHorzScaleBreak = CreateCustomScaleBreak(NColor.Green, new NRange(80, 90)); xScale.ScaleBreaks.Add(m_SecondHorzScaleBreak); NScale yScale = m_Chart.Axes[ENCartesianAxis.PrimaryY].Scale; m_FirstVertScaleBreak = CreateCustomScaleBreak(NColor.Red, new NRange(10, 20)); yScale.ScaleBreaks.Add(m_FirstVertScaleBreak); m_SecondVertScaleBreak = CreateCustomScaleBreak(NColor.Blue, new NRange(80, 90)); yScale.ScaleBreaks.Add(m_SecondVertScaleBreak); chartView.Document.StyleSheets.ApplyTheme(new NChartTheme(ENChartPalette.Bright, false)); return(chartView); }
private void UpdateMiniCharts() { if (m_bLockUpdate == true) { return; } m_Chart.RemoveDescendantsOfType(typeof(NAnchorPanel)); m_Chart.Series.Clear(); // add bar and change bar color m_PointSeries = (NPointSeries)m_Chart.Series.Add(SeriesType.Point); // use custom X positions m_PointSeries.UseXValues = true; m_PointSeries.Size = new NLength(12, NRelativeUnit.ParentPercentage); // this will require to set the InflateMargins flag to true since in this mode // scale is determined only by the X positions of the shape and will not take // into account the size of the bubbles. m_PointSeries.InflateMargins = true; m_PointSeries.PointShape = (PointShape)PointStyleComboBox.SelectedIndex; m_PointSeries.DataLabelStyle.Visible = false; // populate the shape series of the master chart int i = 0; for (i = 0; i < 5; i++) { float fShapeSize = 40 + Random.Next(5); m_PointSeries.XValues.Add(Random.Next(10)); m_PointSeries.Values.Add(Random.Next(10)); m_PointSeries.FillStyles[i] = new NColorFillStyle(RandomColor()); } // create anchor panels attached to the shape series data points for (i = 0; i < m_PointSeries.Values.Count; i++) { NAnchorPanel anchorPanel = new NAnchorPanel(); m_Chart.ChildPanels.Add(anchorPanel); anchorPanel.Size = new NSizeL( new NLength(10, NRelativeUnit.ParentPercentage), new NLength(10, NRelativeUnit.ParentPercentage)); anchorPanel.Anchor = new NDataPointAnchor(m_PointSeries, i, ContentAlignment.MiddleCenter, StringAlignment.Near); anchorPanel.ContentAlignment = ContentAlignment.MiddleCenter; anchorPanel.ChildPanels.Add(CreateAnchorPanelChart()); } nChartControl1.Refresh(); }
private void GenerateXYData(NPointSeries point) { point.ClearDataPoints(); int numberOfGroups = NumberOfPointGroupsDropDownList.SelectedIndex + 1; int numberOfPointsInGroup = (NumberOfPointsInGroupDropDownList.SelectedIndex + 1) * 10000; for (int i = 0; i < numberOfGroups; i++) { AddPointGroup(point, numberOfPointsInGroup); } }
public override void Initialize() { base.Initialize(); // set a chart title NLabel title = nChartControl1.Labels.AddHeader("2D Point Chart Droplines"); title.TextStyle.FontStyle = new NFontStyle("Times New Roman", 18, FontStyle.Italic); // setup chart NChart chart = nChartControl1.Charts[0]; chart.BoundsMode = BoundsMode.Stretch; // add interlace stripe NLinearScaleConfigurator linearScale = chart.Axis(StandardAxis.PrimaryY).ScaleConfigurator as NLinearScaleConfigurator; NScaleStripStyle stripStyle = new NScaleStripStyle(new NColorFillStyle(Color.Beige), null, true, 0, 0, 1, 1); stripStyle.Interlaced = true; stripStyle.SetShowAtWall(ChartWallType.Back, true); stripStyle.SetShowAtWall(ChartWallType.Left, true); linearScale.StripStyles.Add(stripStyle); // setup point series m_Point = (NPointSeries)chart.Series.Add(SeriesType.Point); m_Point.Name = "Point Series"; m_Point.InflateMargins = true; m_Point.UseXValues = true; m_Point.Size = new NLength(10, NGraphicsUnit.Point); m_Point.DataLabelStyle.Visible = false; for (int i = 0; i < 360; i += 5) { double value = Math.Sin(NMath.Degree2Rad * i) * 20; m_Point.XValues.Add(i); m_Point.Values.Add(value); } // apply layout ConfigureStandardLayout(chart, title, nChartControl1.Legends[0]); // init form controls ShowVerticalDropLinesCheckBox.Checked = true; HorizontalDropLinesOriginUpDown.Value = 0; VerticalDropLinesOriginModeComboBox.FillFromEnum(typeof(DropLineOriginMode)); VerticalDropLinesOriginModeComboBox.SelectedIndex = (int)DropLineOriginMode.ScaleMin; ShowHorizontalDropLinesCheckBox.Checked = true; VerticalDropLinesOriginUpDown.Value = 0; HorizontalDropLinesOriginModeComboBox.FillFromEnum(typeof(DropLineOriginMode)); HorizontalDropLinesOriginModeComboBox.SelectedIndex = (int)DropLineOriginMode.ScaleMin; }
private void AddSeries(NChart chart) { // add point series chart.Series.Clear(); NPointSeries point1 = (NPointSeries)chart.Series.Add(SeriesType.Point); point1.Name = "Point 1"; point1.PointShape = PointShape.Bar; point1.Size = new NLength(5, NGraphicsUnit.Point); point1.FillStyle = new NColorFillStyle(Color.Red); point1.BorderStyle.Color = Color.Pink; point1.DataLabelStyle.Visible = false; point1.UseXValues = true; point1.UseZValues = true; point1.InflateMargins = true; NPointSeries point2 = (NPointSeries)chart.Series.Add(SeriesType.Point); point2.Name = "Point 2"; point2.PointShape = PointShape.Bar; point2.Size = new NLength(5, NGraphicsUnit.Point); point2.FillStyle = new NColorFillStyle(Color.CornflowerBlue); point2.BorderStyle.Color = Color.LightCyan; point2.DataLabelStyle.Visible = false; point2.UseXValues = true; point2.UseZValues = true; point2.InflateMargins = true; NPointSeries point3 = (NPointSeries)chart.Series.Add(SeriesType.Point); point3.Name = "Point 3"; point3.PointShape = PointShape.Bar; point3.Size = new NLength(5, NGraphicsUnit.Point); point3.FillStyle = new NColorFillStyle(Color.Green); point3.BorderStyle.Color = Color.Chartreuse; point3.DataLabelStyle.Visible = false; point3.UseXValues = true; point3.UseZValues = true; point3.InflateMargins = true; // fill with random data point1.Values.FillRandomRange(Random, 10, 0, 50); point1.XValues.FillRandomRange(Random, 10, 0, 50); point1.ZValues.FillRandomRange(Random, 10, 0, 50); point2.Values.FillRandomRange(Random, 10, 25, 75); point2.XValues.FillRandomRange(Random, 10, 25, 75); point2.ZValues.FillRandomRange(Random, 10, 25, 75); point3.Values.FillRandomRange(Random, 10, 75, 125); point3.XValues.FillRandomRange(Random, 10, 75, 125); point3.ZValues.FillRandomRange(Random, 10, 75, 125); }
void GenerateData(NChart chart) { NPointSeries series0 = (NPointSeries)chart.Series[0]; NPointSeries series1 = (NPointSeries)chart.Series[1]; const int count = 25; series0.Values.FillRandomRange(Random, count, 0, 50); series0.XValues.FillRandomRange(Random, count, 0, 50); series1.Values.FillRandomRange(Random, count, 25, 75); series1.XValues.FillRandomRange(Random, count, 25, 75); }
protected override void OnTimerTick(object sender, EventArgs e) { base.OnTimerTick(sender, e); NChart chart = nChartControl1.Charts[0]; NAxis axisX = chart.Axis(StandardAxis.PrimaryX); if (m_Counter == 0) { NPointSeries point = new NPointSeries(); point.Size = new NLength(2); point.EnableDepthSort = false; point.DataLabelStyle.Visible = false; point.UseXValues = true; point.UseZValues = true; // turn off point border to improve performance point.BorderStyle.Width = new NLength(0); point.PointShape = PointShape.Bar; point.Tag = new NSphereInfo(DataPointsPerSphereComboBox.SelectedIndex); chart.Series.Add(point); m_Counter = 10; } m_Counter--; int count = chart.Series.Count; for (int i = count - 1; i >= 0; i--) { NPointSeries point = (NPointSeries)chart.Series[i]; NSphereInfo info = (NSphereInfo)point.Tag; if (info.m_Counter == 100) { chart.Series.RemoveAt(i); } else { info.AddSphere(point); } } nChartControl1.Refresh(); }
private void AddNewData(int count) { NPointSeries pointSeries = m_Point; Random rand = new Random(); double[] xValues = new double[count]; double[] yValues = new double[count]; double[] zValues = new double[count]; double centerX = rand.Next(20); double centerY = rand.Next(20); double centerZ = rand.Next(20); for (int i = 0; i < count; i++) { double u1 = rand.NextDouble(); double u2 = rand.NextDouble(); double u3 = rand.NextDouble(); if (u1 == 0) { u1 += 0.0001; } if (u2 == 0) { u2 += 0.0001; } if (u3 == 0) { u3 += 0.0001; } double z0 = centerX + Math.Sqrt(-2 * Math.Log(u1)) * Math.Cos(2 * Math.PI * u2); double z1 = centerY + Math.Sqrt(-2 * Math.Log(u1)) * Math.Sin(2 * Math.PI * u2); double z2 = centerZ + Math.Sqrt(-2 * Math.Log(u1)) * Math.Sin(2 * Math.PI * u3); xValues[i] = z0; yValues[i] = z1; zValues[i] = z2; } pointSeries.XValues.AddRange(xValues); pointSeries.Values.AddRange(yValues); pointSeries.ZValues.AddRange(zValues); UpdateCounter(); nChartControl1.Refresh(); }
/// <summary> /// Return true if dragging can start /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <returns></returns> public override bool CanBeginDrag(object sender, Nevron.Chart.Windows.NMouseEventArgs e) { if (!base.CanBeginDrag(sender, e)) { return(false); } NPoint point = new NPoint(e.X, e.Y); NPointSeries pointSeries = m_DragPlane.PointSeries; NChart chart = pointSeries.Chart; NModel3DToViewTransformation model3DToViewTransformation = new NModel3DToViewTransformation(GetView().Context, chart.Projection); float xHotSpotArea = 10; float yHotSpotArea = 10; int dataPointIndex = -1; for (int i = 0; i < pointSeries.Values.Count; i++) { double x = (double)pointSeries.XValues[i]; double y = (double)pointSeries.Values[i]; double z = (double)pointSeries.ZValues[i]; NVector3DF vecModelPoint; vecModelPoint.X = chart.Axis(StandardAxis.PrimaryX).TransformScaleToModel(false, x); vecModelPoint.Y = chart.Axis(StandardAxis.PrimaryY).TransformScaleToModel(false, y); vecModelPoint.Z = chart.Axis(StandardAxis.Depth).TransformScaleToModel(false, z); NPointF viewPoint = NPointF.Empty; model3DToViewTransformation.Transform(vecModelPoint, ref viewPoint); if (Math.Abs(viewPoint.X - point.X) < xHotSpotArea && Math.Abs(viewPoint.Y - point.Y) < yHotSpotArea) { dataPointIndex = i; break; } } if (dataPointIndex == -1) { return(false); } m_DataPointIndex = dataPointIndex; m_OriginalPosition = m_DragPlane.GetVectorFromPoint(m_DataPointIndex); return(true); }
public override void Initialize() { base.Initialize(); // set a chart title NLabel title = nChartControl1.Labels.AddHeader("XY Scatter Point Chart"); title.TextStyle.FontStyle = new NFontStyle("Times New Roman", 18, FontStyle.Italic); // no legend nChartControl1.Legends.Clear(); // configure the chart NChart chart = nChartControl1.Charts[0]; // setup X axis NLinearScaleConfigurator scaleX = new NLinearScaleConfigurator(); scaleX.MajorGridStyle.ShowAtWalls = new ChartWallType[] { ChartWallType.Back }; scaleX.MajorGridStyle.LineStyle.Pattern = LinePattern.Dot; chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = scaleX; // setup Y axis NLinearScaleConfigurator scaleY = new NLinearScaleConfigurator(); scaleY.MajorGridStyle.ShowAtWalls = new ChartWallType[] { ChartWallType.Back }; scaleY.MajorGridStyle.LineStyle.Pattern = LinePattern.Dot; chart.Axis(StandardAxis.PrimaryY).ScaleConfigurator = scaleY; // add a point series NPointSeries point = (NPointSeries)chart.Series.Add(SeriesType.Point); point.Name = "Point Series"; point.DataLabelStyle.Visible = false; point.FillStyle = new NColorFillStyle(Color.FromArgb(160, DarkOrange)); point.BorderStyle.Width = new NLength(0); point.Size = new NLength(1, NRelativeUnit.ParentPercentage); point.PointShape = PointShape.Ellipse; point.UseXValues = true; GenerateXYData(point); // apply layout ConfigureStandardLayout(chart, title, null); // init form controls AxesRoundToTick.Checked = true; InflateMarginsCheck.Checked = true; }
protected void Page_Load(object sender, EventArgs e) { nChartControl1.BackgroundStyle.FrameStyle.Visible = false; // set a chart title NLabel title = nChartControl1.Labels.AddHeader("Point Chart"); title.TextStyle.FontStyle = new NFontStyle("Times New Roman", 14, FontStyle.Italic); title.TextStyle.ShadowStyle.Type = ShadowType.LinearBlur; // setup chart NChart chart = nChartControl1.Charts[0]; chart.Enable3D = Enable3DCheckBox.Checked; chart.BoundsMode = BoundsMode.Stretch; // add interlace stripe NLinearScaleConfigurator yScale = (NLinearScaleConfigurator)chart.Axis(StandardAxis.PrimaryY).ScaleConfigurator; NScaleStripStyle stripStyle = new NScaleStripStyle(new NColorFillStyle(Color.Beige), null, true, 0, 0, 1, 1); stripStyle.Interlaced = true; stripStyle.SetShowAtWall(ChartWallType.Back, true); stripStyle.SetShowAtWall(ChartWallType.Left, true); yScale.StripStyles.Add(stripStyle); // hide the depth axis chart.Axis(StandardAxis.Depth).Visible = false; // setup point series NPointSeries point = (NPointSeries)chart.Series.Add(SeriesType.Point); point.Name = "Point Series"; point.DataLabelStyle.Visible = false; point.InflateMargins = true; point.AddDataPoint(new NDataPoint(23, "A")); point.AddDataPoint(new NDataPoint(67, "B")); point.AddDataPoint(new NDataPoint(47, "C")); point.AddDataPoint(new NDataPoint(12, "D")); point.AddDataPoint(new NDataPoint(56, "E")); point.AddDataPoint(new NDataPoint(78, "F")); // apply layout ApplyLayoutTemplate(0, nChartControl1, chart, title, null); point.ShowVerticalDropLines = ShowVerticalDropLinesCheckBox.Checked; point.ShowHorizontalDropLines = ShowHorizontalDropLinesCheckBox.Checked; }
public override void Initialize() { base.Initialize(); // set a chart title NLabel title = nChartControl1.Labels.AddHeader("Temperature Measurements <br/><font size = '12pt'>Demonstrates how to Custom Program the Scale</font>"); title.TextStyle.FontStyle = new NFontStyle("Times New Roman", 18, FontStyle.Italic); title.TextStyle.TextFormat = TextFormat.XML; title.SendToBack(); title.DockMode = PanelDockMode.Top; NLegend legend = nChartControl1.Legends[0]; legend.Mode = LegendMode.Disabled; NChart chart = (NCartesianChart)nChartControl1.Charts[0]; chart.BoundsMode = BoundsMode.Stretch; chart.DockMode = PanelDockMode.Fill; chart.DockMargins = new NMarginsL(2, 2, 10, 10); // create a point series NPointSeries point = (NPointSeries)chart.Series.Add(SeriesType.Point); point.Name = "Point Series"; point.DataLabelStyle.Visible = false; point.MarkerStyle.Visible = false; point.Size = new NLength(5, NGraphicsUnit.Point); Random rand = new Random(); for (int i = 0; i < 30; i++) { point.Values.Add(5 + rand.Next(90)); } NAxis primaryY = chart.Axis(StandardAxis.PrimaryY); primaryY.View = new NRangeAxisView(new NRange1DD(0, 100), true, true); NLinearScaleConfigurator linearScale = primaryY.ScaleConfigurator as NLinearScaleConfigurator; linearScale.RoundToTickMax = false; linearScale.RoundToTickMin = false; UpdateScale(); nChartControl1.Refresh(); }
/// <summary> /// Initializer constructor /// </summary> /// <param name="vecA"></param> /// <param name="vecB"></param> /// <param name="vecC"></param> /// <param name="vecD"></param> public NDragPlane(NVector3DD vecA, NVector3DD vecB, NVector3DD vecC, NVector3DD vecD) { NPointSeries pointSeries = new NPointSeries(); pointSeries.Tag = (int)1; pointSeries.PointShape = PointShape.Sphere; pointSeries.UseXValues = true; pointSeries.UseZValues = true; pointSeries.DataLabelStyle.Visible = false; pointSeries.InflateMargins = false; pointSeries.Size = new NLength(8); pointSeries.Values.Add(vecA.Y); pointSeries.XValues.Add(vecA.X); pointSeries.ZValues.Add(vecA.Z); pointSeries.FillStyles[0] = new NColorFillStyle(Color.Red); pointSeries.Values.Add(vecB.Y); pointSeries.XValues.Add(vecB.X); pointSeries.ZValues.Add(vecB.Z); pointSeries.FillStyles[1] = new NColorFillStyle(Color.Blue); pointSeries.Values.Add(vecC.Y); pointSeries.XValues.Add(vecC.X); pointSeries.ZValues.Add(vecC.Z); pointSeries.FillStyles[2] = new NColorFillStyle(Color.Blue); pointSeries.Values.Add(vecD.Y); pointSeries.XValues.Add(vecD.X); pointSeries.ZValues.Add(vecD.Z); pointSeries.FillStyles[3] = new NColorFillStyle(Color.Red); m_PointSeries = pointSeries; NMeshSurfaceSeries meshSeries = new NMeshSurfaceSeries(); meshSeries.Data.SetGridSize(2, 2); m_MeshSurface = meshSeries; m_MeshSurface.FillMode = SurfaceFillMode.Uniform; m_MeshSurface.FrameMode = SurfaceFrameMode.None; m_MeshSurface.FillStyle = new NColorFillStyle(Color.Blue); m_MeshSurface.FillStyle.SetTransparencyPercent(50.0f); UpdateMeshSurface(); }
public override void Initialize() { base.Initialize(); // set a chart title NLabel title = new NLabel("Volume Selection Tool"); title.DockMode = PanelDockMode.Top; title.TextStyle.FontStyle = new NFontStyle("Times New Roman", 18, FontStyle.Italic); title.ContentAlignment = ContentAlignment.BottomCenter; title.Location = new NPointL(new NLength(50, NRelativeUnit.ParentPercentage), new NLength(2, NRelativeUnit.ParentPercentage)); nChartControl1.Panels.Add(title); NChart chart = nChartControl1.Charts[0]; chart.Enable3D = true; chart.BoundsMode = BoundsMode.Fit; chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = new NLinearScaleConfigurator(); chart.Axis(StandardAxis.Depth).ScaleConfigurator = new NLinearScaleConfigurator(); chart.Width = chart.Height = chart.Depth = 50; chart.Projection.SetPredefinedProjection(PredefinedProjection.PerspectiveTilted); NPointSeries point = new NPointSeries(); point.UseXValues = true; point.UseZValues = true; point.DataLabelStyle.Visible = false; point.InflateMargins = true; Random rand = new Random(); for (int i = 0; i < 100; i++) { point.Values.Add(rand.Next(100)); point.XValues.Add(rand.Next(100)); point.ZValues.Add(rand.Next(100)); } chart.Series.Add(point); ActiveToolComboBox.Items.Add("Trackball"); ActiveToolComboBox.Items.Add("Volume Selector"); ActiveToolComboBox.SelectedIndex = 1; }
/// <summary> /// Demonstrates the use of Savitzky-Golay smoothing filter. /// </summary> void DataSmoothing() { // Set up example description nRichDescription.Text = "Smoothing discrete data with random normal noise using a 5th degree Savitzky-Golay filter. \n\nWhen using the Savitzky-Golay filter class, both the degree of the fitting polynomial and the filter width can be easily controlled. Good defaults are available."; // Create an interesting noisy sampled signal to smooth. DoubleVector xs = new DoubleVector(50, 0, Math.PI / 25); RandomNumberGenerator rand = new RandGenNormal(0.0, noiselevel_); DoubleVector raw_data = 10.0 * NMathFunctions.Tanh(NMathFunctions.Sin(xs)) + 0.2 * new DoubleVector(xs.Length, rand); // Create the filter and smooth the data MovingWindowFilter filter = new MovingWindowFilter(10, 10, MovingWindowFilter.SavitzkyGolayCoefficients(10, 10, 5)); DoubleVector smoothed_data = filter.Filter(raw_data, MovingWindowFilter.BoundaryOption.PadWithZeros); SetupChartLayout("Data Smoothing"); NChart chart = nChartControl1.Charts[0]; SetupChartAxes(chart); // Create a point series to display the raw data NPointSeries point = new NPointSeries(); chart.Series.Add(point); // Tell the series to regard the X values point.UseXValues = true; // Points must fit in the chart area point.InflateMargins = true; // No data labels point.DataLabelStyle.Visible = false; // Set up the data look and feel point.FillStyle = new NColorFillStyle(Color.SkyBlue); point.BorderStyle = new NStrokeStyle(1.0f, Color.DarkGray); point.PointShape = PointShape.Ellipse; point.Size = new NLength(4.0f); // Name points point.Name = "Observations"; // Load data into points collection point.XValues.AddRange(xs.DataBlock.Data); point.Values.AddRange(raw_data.DataBlock.Data); // Create a line series to display the smoothed data NLineSeries smoothline = new NLineSeries(); chart.Series.Add(smoothline); smoothline.UseXValues = true; smoothline.DataLabelStyle.Visible = false; smoothline.BorderStyle = new NStrokeStyle(2.0f, Color.Tomato); // Name smooth line smoothline.Name = "Savitzky-Golay Smoothed Data"; // Load the smoothed data into the line series smoothline.XValues.AddRange(xs.DataBlock.Data); smoothline.Values.AddRange(smoothed_data.DataBlock.Data); nChartControl1.Refresh(); }
/// <summary> /// Demonstrates polynomial least squares curve fitting /// </summary> void CurveFitting() { // Set up example description nRichDescription.Text = "A 4th degree polynomial is fitted to the noisy sampled data. \n\nFitting a polynomial of any degree is accomplished in one line of code specifing the polynomial degree, and arrays of the x and y values. "; // Build the data sets using some random normal noise DoubleVector x = new DoubleVector("[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2 2.1 2.2 2.3 2.4 2.5]"); DoubleVector y = new DoubleVector("[0 0.112462916018285 0.222702589210478 0.328626759459127 0.428392355046668 0.520499877813047 0.603856090847926 0.677801193837419 0.742100964707661 0.796908212422832 0.842700792949715 0.880205069574082 0.910313978229635 0.934007944940652 0.952285119762649 0.966105146475311 0.976348383344644 0.983790458590775 0.989090501635731 0.992790429235257 0.995322265018953 0.997020533343667 0.998137153702018 0.998856823402643 0.999311486103355 0.999593047982555]"); RandomNumberGenerator rand = new RandGenNormal(0.0, noiselevel_); y = y + 0.025 * (new DoubleVector(y.Length, rand)); // Build the least squares polynomial fit and make readable display label int polynomialdeg = 4; PolynomialLeastSquares pls = new PolynomialLeastSquares(polynomialdeg, x, y); // Build fitted polynomial DoubleVector xs = new DoubleVector(100, 0, 0.025); DoubleVector ys = pls.FittedPolynomial.Evaluate(xs); // Build the chart SetupChartLayout("Curve Fitting"); NChart chart = nChartControl1.Charts[0]; SetupChartAxes(chart); // Draw the raw data points NPointSeries point = new NPointSeries(); chart.Series.Add(point); point.UseXValues = true; point.DataLabelStyle.Visible = false; // set some appearance properties point.FillStyle = new NColorFillStyle(Color.SkyBlue); point.BorderStyle = new NStrokeStyle(1.0f, Color.DarkGray); point.PointShape = PointShape.Star; point.Size = new NLength(6.0f); // Points must fit in the chart area point.InflateMargins = true; // Name points data set point.Name = "Observations"; // Add data points from the NMath DoubleVectors to the point series point.Values.AddRange(y.DataBlock.Data); point.XValues.AddRange(x.DataBlock.Data); // Build polynomial line series and style it NLineSeries polyline = new NLineSeries(); chart.Series.Add(polyline); polyline.UseXValues = true; polyline.DataLabelStyle.Visible = false; polyline.BorderStyle = new NStrokeStyle(2.0f, Color.Tomato); // Name polynomial fit polyline.Name = polynomialdeg.ToString() + "th Degree Polynomial"; // Load the polynomial data into the line series polyline.XValues.AddRange(xs.DataBlock.Data); polyline.Values.AddRange(ys.DataBlock.Data); // Create a label to display the polynomial NLabel label = new NLabel(); label.BoundsMode = BoundsMode.None; label.ContentAlignment = ContentAlignment.MiddleLeft; label.Location = new NPointL( new NLength(92, NRelativeUnit.ParentPercentage), new NLength(70, NRelativeUnit.ParentPercentage)); label.TextStyle.TextFormat = TextFormat.XML; label.TextStyle.FontStyle = new NFontStyle("Arial", 9); label.TextStyle.StringFormatStyle.HorzAlign = Nevron.HorzAlign.Center; label.TextStyle.BackplaneStyle.Visible = true; label.TextStyle.BackplaneStyle.FillStyle = new NGradientFillStyle(GradientStyle.Horizontal, GradientVariant.Variant1, Color.FromArgb(180, 255, 255, 255), Color.FromArgb(180, 233, 233, 255)); label.TextStyle.BackplaneStyle.Shape = BackplaneShape.Rectangle; label.TextStyle.BackplaneStyle.StandardFrameStyle.InnerBorderColor = Color.FromArgb(200, 200, 255); label.Text = "Equation for fitted polynomial:<br /><font size='10' color = 'tomato'><b>"; label.Text += FormatPolymonial(pls.FittedPolynomial.Coeff.ToArray()); label.Text += "</b></font>"; chart.ChildPanels.Add(label); nChartControl1.Refresh(); }
private void SubPieceMarkup(int pieceNum) { SplitPieces SubPieces = GradeVariable.SplitPiecesContainer[pieceNum]; foreach (RoiGrade r in GradeVariable.RoiRowsGrid) { foreach (RoiGrade c in GradeVariable.RoiColumnsGrid) { foreach (SplitPiece s in SubPieces.Pieces) { if (s.Name == string.Format("ROI-{0}{1}", r.Name, c.Name)) { NPointSeries labels = new NPointSeries(); labels.Name = "Markup"; labels.UseXValues = true; labels.MarkerStyle.Visible = false; labels.DataLabelStyle.Format = "<label>"; labels.BorderStyle.Width = new NLength(0); labels.FillStyle.SetTransparencyPercent(100); labels.DataLabelStyle.TextStyle.FontStyle = new NFontStyle("Consolas", new NLength(12, NGraphicsUnit.Point), FontStyle.Bold); labels.DataLabelStyle.TextStyle.FillStyle = new NColorFillStyle(Color.Blue); labels.DataLabelStyle.TextStyle.BackplaneStyle.Visible = false; labels.DataLabelStyle.TextStyle.Orientation = 0; labels.DataLabelStyle.TextStyle.StringFormatStyle.HorzAlign = Nevron.HorzAlign.Left; labels.DataLabelStyle.TextStyle.StringFormatStyle.VertAlign = Nevron.VertAlign.Top; labels.DataLabelStyle.ArrowLength = new NLength(0); labels.Values.Add((r.End - (r.End - r.Start) * 0.15)); labels.XValues.Add((c.Start + (c.End - c.Start) * 0.05)); labels.Labels.Add(string.Format("{0} - {1}({2})", s.Name, s.Score, s.GradeLevel)); nChartMap.Series.Add(labels); } } } } }
/// <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); }
/// <summary> /// Demonstrates linear reression in two dimensions. /// </summary> void LinearRegression() { // Set up example description nRichDescription.Text = "A linear regression model is computed from the sample data containing random normal noise. \n\nA point is then predicted from the model with a 95% confidence interval - meaning the predicted point is expected to lie within the confidence interval 95% of the time."; // First read in the independent (or predictor) values. This is a matrix // with one column and a row for each amounts measurement. DoubleVector raw_data = new DoubleVector(25, 0, 1); DoubleMatrix measurements = new DoubleMatrix(raw_data); // Next, read in the responses // Build a linear polynomial and add noise for interest RandomNumberGenerator rand = new RandGenNormal(0, noiselevel_); Polynomial poly = new Polynomial(new DoubleVector("0, 1")); DoubleVector responses = poly.Evaluate(raw_data) + new DoubleVector(raw_data.Length, rand); ; // Construct a linear regression. If we want our regression to calculate a // y-intercept we must send in true for the "addIntercept" parameter (the // third paramameter in the constructor). LinearRegression regression = new LinearRegression(measurements, responses, true); DoubleVector residues = regression.Residuals; // Use the linear regression class to make a prediction according to the model DoubleVector xvalues = new DoubleVector("30"); // Use the model to predict the observation at 30. Interval pi = regression.PredictionInterval(xvalues, 0.95); // Build some data points along the regression line for display DoubleMatrix abcissae = new DoubleMatrix(new DoubleVector(raw_data)); DoubleVector predicted_ys = regression.PredictedObservations(abcissae); // Build the chart SetupChartLayout("Linear Regression"); NChart chart = nChartControl1.Charts[0]; SetupChartAxes(chart); // Set up the line series NLineSeries line = new NLineSeries(); chart.Series.Add(line); // tell the series to regard the X values line.UseXValues = true; // no data labels line.DataLabelStyle.Visible = false; // Set the line color line.BorderStyle = new NStrokeStyle(2.0f, Color.Tomato); // name data set line.Name = "Linear Regression"; // Add the the Linear Regression line data to the line series line.XValues.AddRange(abcissae.DataBlock.Data); line.Values.AddRange(predicted_ys.DataBlock.Data); // Draw the raw data points NPointSeries point = new NPointSeries(); chart.Series.Add(point); point.UseXValues = true; point.DataLabelStyle.Visible = false; // Set the point appearance properties point.FillStyle = new NColorFillStyle(Color.SkyBlue); point.BorderStyle = new NStrokeStyle(1.0f,Color.DarkGray); point.PointShape = PointShape.Cross; point.Size = new NLength(6.0f); // Points must fit in the chart area point.InflateMargins = true; // Name point set point.Name = "Observations"; // set the point data point.Values.AddRange(responses.DataBlock.Data); point.XValues.AddRange(measurements.DataBlock.Data); double m = (pi.Min + pi.Max) / 2.0; // Display the predicted value with an error bar series NErrorBarSeries predicted_points = new NErrorBarSeries(); chart.Series.Add(predicted_points); predicted_points.Name = "Predicted Point"; predicted_points.UseXValues = true; predicted_points.InflateMargins = true; predicted_points.FillStyle = new NColorFillStyle(Color.Crimson); predicted_points.BorderStyle = new NStrokeStyle(1.0f, Color.DarkGray); predicted_points.DataLabelStyle.Visible = false; predicted_points.MarkerStyle.Visible = true; predicted_points.MarkerStyle.FillStyle = new NColorFillStyle(Color.Crimson); predicted_points.MarkerStyle.BorderStyle = new NStrokeStyle(1.0f, Color.DarkGray); predicted_points.MarkerStyle.PointShape = PointShape.Bar; predicted_points.MarkerStyle.Width = new NLength(5); predicted_points.MarkerStyle.Height = new NLength(5); predicted_points.SizeY = new NLength(5); // Fill the data for the predicted point predicted_points.XValues.AddRange(xvalues.DataBlock.Data); predicted_points.Values.Add(m); predicted_points.UpperErrorsY.Add(pi.Max - m); predicted_points.LowerErrorsY.Add(m - pi.Min); // Create a label to display the predicted value NLabel label = new NLabel(); label.BoundsMode = BoundsMode.None; label.ContentAlignment = ContentAlignment.BottomLeft; label.Location = new NPointL( new NLength(87, NRelativeUnit.ParentPercentage), new NLength(3, NRelativeUnit.ParentPercentage)); label.TextStyle.TextFormat = TextFormat.XML; label.TextStyle.FontStyle = new NFontStyle("Arial", 9); label.TextStyle.StringFormatStyle.HorzAlign = Nevron.HorzAlign.Right; label.TextStyle.BackplaneStyle.Visible = true; label.TextStyle.BackplaneStyle.FillStyle = new NGradientFillStyle(GradientStyle.Horizontal, GradientVariant.Variant1, Color.FromArgb(130, 255, 255, 255), Color.FromArgb(130, 233, 233, 255)); label.TextStyle.BackplaneStyle.Shape = BackplaneShape.SmoothEdgeRectangle; label.TextStyle.BackplaneStyle.StandardFrameStyle.InnerBorderColor = Color.White; label.Text = "<font color = 'crimson'>" + m.ToString("0.###") + "</font> - predicted value with 95% confidence interval"; chart.ChildPanels.Add(label); nChartControl1.Refresh(); }