Profile Picture

Cartesian chart: How to preserve the current zoom setting, redraw the chart, then reapply the zoom

Posted By Kevin Harrison 4 Years Ago

Cartesian chart: How to preserve the current zoom setting, redraw the...

Author
Message
Kevin Harrison
Question Posted 4 Years Ago
View Quick Profile
Supreme Being

Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 173, Visits: 1,673

Hopefully the title is self-explanatory. We have several instances where:
1) A chart is rendered and the the DataZoom tool is used to expand a specific region.
2) There is some reason to redraw the chart
3) We want the original zoom setting to be reapplied, as though the user had reused the DataZoom tool; i.e. with the ability to zoom back out to see the full chart.
What is the easiest way to achieve this? I can see that I can probably use RulerRanges to read the current zoom settings and preserve them. However, how do I "reapply" the zoom in code after redrawing the chart? If I just apply the RulerRanges I do not have the ability to zoom back out.
Thanks
Kevin



Nevron Support
Posted 4 Years Ago
View Quick Profile
Supreme Being

Supreme Being (3,905 reputation)Supreme Being (3,905 reputation)Supreme Being (3,905 reputation)Supreme Being (3,905 reputation)Supreme Being (3,905 reputation)Supreme Being (3,905 reputation)Supreme Being (3,905 reputation)Supreme Being (3,905 reputation)Supreme Being (3,905 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 2,879, Visits: 3,045

Hi Kevin,
The easiest way to zoom back to the origin is to disable paging:

chart.Axis[StandardAxis.PrimaryX].PagingView.Enabled = false;

In order to zoom in to a specified range you can use the Zoom in method of the paging view:

chart.Axis(StandardAxis.PrimaryX).PagingView.ZoomIn(new Nevron.GraphicsCore.NRange1DD(0, 1), 0.001);

Hope this helps - let us know if you meet any problems or have any questions.



Best Regards,
Nevron Support Team



Kevin Harrison
Posted 4 Years Ago
View Quick Profile
Supreme Being

Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 173, Visits: 1,673
Works perfectly. Thanks guys.
Kevin

Kevin Harrison
Posted Last Year
View Quick Profile
Supreme Being

Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 173, Visits: 1,673
As an update for this, is there a way for me to know when a zoom event has completed, so I can read the ranges at this point and store them?

I tried adding code to OnEndDrag in an overridden NDataZoomTool class, but axis.Scale.RulerRange hasn't been updated at this stage. I couldn't see anything else to hook into in this class.

Thanks

Kevin

Nevron Support
Posted Last Year
View Quick Profile
Supreme Being

Supreme Being (3,905 reputation)Supreme Being (3,905 reputation)Supreme Being (3,905 reputation)Supreme Being (3,905 reputation)Supreme Being (3,905 reputation)Supreme Being (3,905 reputation)Supreme Being (3,905 reputation)Supreme Being (3,905 reputation)Supreme Being (3,905 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 2,879, Visits: 3,045
Hi Kevin,

The scale range is recalculated when the control is recalculated. You can force recalculation when you receive the EndZoom event and then retrieve the range - for example:

  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(20);
    chart.Series.Add(bar);

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

    NDataZoomTool dataZoomTool = new NDataZoomTool();
    dataZoomTool.EndDrag += DataZoomTool_EndDrag;
    
    nChartControl1.Controller.Tools.Add(dataZoomTool);
   }

   private void DataZoomTool_EndDrag(object sender, EventArgs e)
   {
    NDataZoomTool dataZoomTool = (NDataZoomTool)sender;

    nChartControl1.RecalcLayout();
    NRange1DD range = nChartControl1.Charts[0].Axis(StandardAxis.PrimaryX).Scale.RulerRange;

    Trace.WriteLine("X:" + range.Begin.ToString() + ", Y:" + range.End.ToString());
   }

Let us know if you meet any problems or have any questions.

Best Regards,
Nevron Support Team



Kevin Harrison
Posted Last Year
View Quick Profile
Supreme Being

Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 173, Visits: 1,673
Thanks. My override of the tool is in a separate class so I don't have direct access to nChartControl1. What's the best way to get it form within the OnEndDrag override please?

Kevin Harrison
Posted Last Year
View Quick Profile
Supreme Being

Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 173, Visits: 1,673
I tried RecalcLayout and it doesn't work. The RulerRanges are unchanged.

I also note that OnEndDrag is entered for the tool just by clicking on the chart, so it might be useful for me to determine whether the mouse has moved.

Thanks
Kevin

Nevron Support
Posted Last Year
View Quick Profile
Supreme Being

Supreme Being (3,905 reputation)Supreme Being (3,905 reputation)Supreme Being (3,905 reputation)Supreme Being (3,905 reputation)Supreme Being (3,905 reputation)Supreme Being (3,905 reputation)Supreme Being (3,905 reputation)Supreme Being (3,905 reputation)Supreme Being (3,905 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 2,879, Visits: 3,045
Hi Kevin,
You can call:
this.GetView().RecalcLayout();
from the derived data zoom tool class. We were not able to replicate the case where the ruler range will not update properly - can you send us some code replicating this?

Best Regards,
Nevron Support Team





Similar Topics


Reading This Topic