Nevron Forum

NDataZoomTool Save / Restore Selected Range

https://www.nevron.com/Forum/Topic12777.aspx

By Timothy Dishop 1 - Tuesday, May 21, 2019

Is there a way to save the current zoom and then restore it?

I have issues where the chart is cleared and restored during different events. It seems that it would be easiest to save the zoom and restore it on the new view.

Thanks 

Jim
By Nevron Support - Tuesday, May 21, 2019

Hi James,

The zoom information is stored in the PagingView object attached to the axis. In order to save / restore the zoom level for a particular axis you can clone the view object and then assign it later to the axis when you want to restore the zoom to a previous state. The following code example shows how to do that:
private void Form1_Load(object sender, EventArgs e)
{
    NCartesianChart chart = (NCartesianChart)nChartControl1.Charts[0];
    chart.RangeSelections.Add(new NRangeSelection());

    NBarSeries bar = new NBarSeries();
    bar.Values.Add(10);
    bar.Values.Add(20);
    bar.Values.Add(30);
    chart.Series.Add(bar);

    nChartControl1.Controller.Tools.Add(new NPanelSelectorTool());
    nChartControl1.Controller.Tools.Add(new NDataZoomTool());
   }

   NAxisPagingView xView;
   NAxisPagingView yView;

   private void button1_Click(object sender, EventArgs e)
   {
    NCartesianChart chart = (NCartesianChart)nChartControl1.Charts[0];
    xView = (NAxisPagingView)chart.Axis(StandardAxis.PrimaryX).PagingView.Clone();
    yView = (NAxisPagingView)chart.Axis(StandardAxis.PrimaryY).PagingView.Clone();
   }

   private void button2_Click(object sender, EventArgs e)
   {
    NCartesianChart chart = (NCartesianChart)nChartControl1.Charts[0];
    chart.Axis(StandardAxis.PrimaryX).PagingView = (NAxisPagingView)xView.Clone();
    chart.Axis(StandardAxis.PrimaryY).PagingView = (NAxisPagingView)yView.Clone();

    nChartControl1.Refresh();
   }
Hope we helped - let us know if you meet any problems or have any questions.
By Nevron Support - Wednesday, May 22, 2019

Hi James,
The scrollbar will fire the reset event when clicked:
   chart.Axis(StandardAxis.PrimaryX).ScrollBar.Reset += ScrollBar_Reset;
...
   private void ScrollBar_Reset(object sender, EventArgs e)
   {
    MessageBox.Show("Reset pressed");
   }

Let us know if you meet any problems...
By Timothy Dishop 1 - Wednesday, May 22, 2019

Is there a way to capture when the red circle close button click?
By Timothy Dishop 1 - Friday, May 24, 2019

The one issue I just noticed is that when I initially zoom to one month in a year of data the x scale is in days.  When I set it to the cloned data the x scale is in months?
By Nevron Support - Monday, May 27, 2019

Hi James,
Can you send us a small code snippet that replicates that?