protected void nChartControl2_AsyncCustomCommand(object sender, EventArgs e) { NCallbackCustomCommandArgs args = e as NCallbackCustomCommandArgs; switch (args.Command.Name) { case "displayDataWindow": double dataWindowWidth = double.Parse(args.Command.Arguments["width"] as string); NCartesianChart zoomChart = nChartControl2.Charts[0] as NCartesianChart; NSmoothLineSeries zoomLine = zoomChart.Series[0] as NSmoothLineSeries; NCartesianChart previewChart = nChartControl1.Charts[0] as NCartesianChart; NAxis previewXAxis = previewChart.Axis(StandardAxis.PrimaryX); NPointF ptViewPoint = new NPointF(float.Parse(args.Command.Arguments["x"] as string), 0); NVector2DD vecScalePoint = new NVector2DD(); using (NChartRasterView view = new NChartRasterView(nChartControl1.Document, nChartControl1.Dimensions, NResolution.ScreenResolution)) { view.RecalcLayout(); NViewToScale2DTransformation viewToScale = new NViewToScale2DTransformation( view.Context, previewChart, (int)StandardAxis.PrimaryX, (int)StandardAxis.PrimaryY ); if (viewToScale.Transform(ptViewPoint, ref vecScalePoint)) { double rangeMin = vecScalePoint.X - dataWindowWidth / 2; rangeMin = previewXAxis.Scale.ViewRange.GetValueInRange(rangeMin); double rangeMax = rangeMin + dataWindowWidth; rangeMax = previewXAxis.Scale.ViewRange.GetValueInRange(rangeMax); rangeMin = rangeMax - dataWindowWidth; // reinitialize data points zoomLine.XValues.Clear(); zoomLine.Values.Clear(); for (int i = (int)rangeMin; i <= (int)rangeMax; i++) { zoomLine.XValues.Add(i); zoomLine.Values.Add(waveData[i]); } } } break; } }
void UpdateDataWindow(string webControlId, System.Web.HttpContext context, NStateObject state, NPointF ptViewPoint) { NChartSessionStateObject chartState = state as NChartSessionStateObject; NRootPanel rootPanel = chartState.Document.RootPanel; NCartesianChart chart = rootPanel.Charts[0] as NCartesianChart; NVector2DD vecScalePoint = new NVector2DD(); NAxis xAxis = chart.Axis(StandardAxis.PrimaryX); NAxis yAxis = chart.Axis(StandardAxis.PrimaryY); using (NChartRasterView view = new NChartRasterView(chartState.Document, chartState.Size, NResolution.ScreenResolution)) { view.RecalcLayout(); NViewToScale2DTransformation viewToScale = new NViewToScale2DTransformation( view.Context, chart, (int)StandardAxis.PrimaryX, (int)StandardAxis.PrimaryY ); if (viewToScale.Transform(ptViewPoint, ref vecScalePoint)) { double rangeMin = vecScalePoint.X - DataWindowWidth / 2; rangeMin = xAxis.Scale.ViewRange.GetValueInRange(rangeMin); double rangeMax = rangeMin + DataWindowWidth; rangeMax = xAxis.Scale.ViewRange.GetValueInRange(rangeMax); rangeMin = rangeMax - DataWindowWidth; NRangeSelection selection = chart.RangeSelections[0] as NRangeSelection; selection.HorizontalAxisRange = new NRange1DD(rangeMin, rangeMax); selection.VerticalAxisRange = new NRange1DD(-waveDataWave1Factor, waveDataWave1Factor); } } }