protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { // fill the combo WebExamplesUtilities.FillComboWithValues(XValueDropDownList, 10, 90, 10); WebExamplesUtilities.FillComboWithValues(YValueDropDownList, 10, 90, 10); } nChartControl1.BackgroundStyle.FrameStyle.Visible = false; nChartControl1.Settings.JitterMode = JitterMode.Enabled; // set a chart title NLabel title = nChartControl1.Labels.AddHeader("Intersect Line With X/Y Value"); title.TextStyle.FontStyle = new NFontStyle("Times New Roman", 14, FontStyle.Italic); title.TextStyle.ShadowStyle.Type = ShadowType.LinearBlur; NChart chart = nChartControl1.Charts[0]; // 2D line chart chart.BoundsMode = BoundsMode.Stretch; chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = GetScaleConfigurator(); chart.Axis(StandardAxis.PrimaryY).ScaleConfigurator = GetScaleConfigurator(); chart.Axis(StandardAxis.Depth).Visible = false; NAxisCollection axes = chart.Axes; // add point series NPointSeries point = (NPointSeries)chart.Series.Add(SeriesType.Point); point.UseXValues = true; point.FillStyle = new NColorFillStyle(Color.Red); point.DataLabelStyle.Visible = false; point.Size = new NLength(2); NLineSeries line = new NLineSeries(); chart.Series.Add(line); line.Name = "Point 1"; line.FillStyle = new NColorFillStyle(Color.Red); line.BorderStyle.Color = Color.Pink; line.DataLabelStyle.Visible = false; line.UseXValues = true; line.InflateMargins = true; // fill with data Random rand = new Random(); double radius = 0; double angle = 0; int dataPointCount = 1000; double rStep = 50.0 / dataPointCount; double aStep = 10.0; for (int i = 0; i < dataPointCount; i++) { double y = Math.Sin(angle * 0.0174533f) * radius; double x = Math.Cos(angle * 0.0174533f) * radius; line.XValues.Add(50.0 + x); line.Values.Add(50.0 + y); radius += rStep; angle += aStep; } point.XValues.Clear(); point.Values.Clear(); NAxisConstLine horizontalAxisCursor = new NAxisConstLine(); NAxisConstLine verticalAxisCursor = new NAxisConstLine(); chart.Axis(StandardAxis.PrimaryX).ConstLines.Add(horizontalAxisCursor); chart.Axis(StandardAxis.PrimaryY).ConstLines.Add(verticalAxisCursor); double xValue = (XValueDropDownList.SelectedIndex + 1) * 10; double yValue = (YValueDropDownList.SelectedIndex + 1) * 10; horizontalAxisCursor.Value = xValue; List <double> intersections = line.IntersectWithXValue(xValue); for (int i = 0; i < intersections.Count; i++) { point.XValues.Add(xValue); point.Values.Add(intersections[i]); } verticalAxisCursor.Value = yValue; intersections = line.IntersectWithYValue(yValue); for (int i = 0; i < intersections.Count; i++) { point.XValues.Add(intersections[i]); point.Values.Add(yValue); } // apply layout ApplyLayoutTemplate(0, nChartControl1, chart, title, null); }
/// <summary> /// Called to initialize the example /// </summary> /// <param name="chartControl"></param> public override void Create() { // turn off the legend nChartControl1.Legends[0].Visible = false; // set a chart title NLabel title = nChartControl1.Labels.AddHeader("Intersect Line with X/Y Value"); title.TextStyle.FontStyle = new NFontStyle("Times New Roman", 18, System.Drawing.FontStyle.Italic); title.ContentAlignment = ContentAlignment.BottomCenter; title.Location = new NPointL(new NLength(50, NRelativeUnit.ParentPercentage), new NLength(2, NRelativeUnit.ParentPercentage)); // configure the chart NChart m_Chart = nChartControl1.Charts[0]; m_HorizontalAxisCursor = new NAxisCursor(); m_HorizontalAxisCursor.BeginEndAxis = (int)StandardAxis.PrimaryY; m_HorizontalAxisCursor.ValueChanged += new EventHandler(OnAxisCursorValueChanged); m_VerticalAxisCursor = new NAxisCursor(); m_VerticalAxisCursor.BeginEndAxis = (int)StandardAxis.PrimaryX; m_VerticalAxisCursor.ValueChanged += new EventHandler(OnAxisCursorValueChanged); m_Chart.Axis(StandardAxis.PrimaryX).Cursors.Add(m_HorizontalAxisCursor); m_Chart.Axis(StandardAxis.PrimaryY).Cursors.Add(m_VerticalAxisCursor); m_HorizontalAxisCursor.SynchronizeOnMouseAction |= MouseAction.Move; m_VerticalAxisCursor.SynchronizeOnMouseAction |= MouseAction.Move; // 2D line chart m_Chart.Series.Clear(); m_Chart.BoundsMode = BoundsMode.Stretch; m_Chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = GetScaleConfigurator(); m_Chart.Axis(StandardAxis.PrimaryY).ScaleConfigurator = GetScaleConfigurator(); m_Chart.Axis(StandardAxis.Depth).Visible = false; NAxisCollection axes = m_Chart.Axes; m_Chart.Location = new NPointL( new NLength(10, NRelativeUnit.ParentPercentage), new NLength(12, NRelativeUnit.ParentPercentage)); m_Chart.Size = new NSizeL( new NLength(80, NRelativeUnit.ParentPercentage), new NLength(78, NRelativeUnit.ParentPercentage)); // add point series m_Point = (NPointSeries)m_Chart.Series.Add(SeriesType.Point); m_Point.UseXValues = true; m_Point.FillStyle = new NColorFillStyle(Color.Red); m_Point.DataLabelStyle.Visible = false; m_Point.Size = new NLength(2); m_Line = (NLineSeries)m_Chart.Series.Add(SeriesType.Line); m_Line.Name = "Point 1"; m_Line.FillStyle = new NColorFillStyle(Color.Red); m_Line.BorderStyle.Color = Color.Pink; m_Line.DataLabelStyle.Visible = false; m_Line.UseXValues = true; m_Line.InflateMargins = true; // fill with random data Random rand = new Random(); double radius = 1000; double angle = 0; double rStep = 10; double aStep = 10; for (int i = 0; i < 1000; i++) { double y = Math.Sin(angle * 0.0174533f) * radius; double x = Math.Cos(angle * 0.0174533f) * radius; m_Line.XValues.Add(x); m_Line.Values.Add(y); radius += rStep; angle += aStep; } nChartControl1.Controller.Tools.Clear(); nChartControl1.Controller.Selection.SelectedObjects.Add(m_Chart); nChartControl1.Controller.Tools.Add(new NDataCursorTool()); }