The following code shows how to create a chart that zooms simultaneously on two axes (PrimaryY and SecondaryY):
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Nevron.Chart;
using Nevron.GraphicsCore;
using Nevron.Chart.WinForm;
using Nevron.SmartShapes;
using System.IO;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
NRangeSelection m_RangeSelection;
NCartesianChart m_Chart;
private void Form1_Load(object sender, EventArgs e)
{
m_Chart = (NCartesianChart)nChartControl1.Charts[0];
m_RangeSelection = new NRangeSelection();
m_Chart.RangeSelections.Add(m_RangeSelection);
NLineSeries line1 = new NLineSeries();
NLineSeries line2 = new NLineSeries();
for (int i = 0; i < 10; i++)
{
line1.Values.Add(i);
line2.Values.Add((10 - i) * 10);
}
m_Chart.Series.Add(line1);
m_Chart.Series.Add(line2);
line2.DisplayOnAxis(StandardAxis.PrimaryY, false);
line2.DisplayOnAxis(StandardAxis.SecondaryY, true);
m_Chart.Axis(StandardAxis.SecondaryY).Visible = true;
nChartControl1.Controller.Tools.Add(new NSelectorTool());
NDataZoomTool dzt = new NDataZoomTool();
dzt.EndDrag += new EventHandler(dzt_EndDrag);
nChartControl1.Controller.Tools.Add(dzt);
}
void dzt_EndDrag(object sender, EventArgs e)
{
NRange1DD horzRange = m_RangeSelection.HorizontalAxisRange;
NRange1DD vertRange = m_RangeSelection.VerticalAxisRange;
// gt relative y disposition of selected range
double beginYFactor = m_Chart.Axis(StandardAxis.PrimaryY).Scale.ViewRange.GetValueFactor(horzRange.Begin);
double endYFactor = m_Chart.Axis(StandardAxis.PrimaryY).Scale.ViewRange.GetValueFactor(horzRange.End);
NRange1DD axisRange = m_Chart.Axis(StandardAxis.SecondaryY).Scale.ViewRange;
double beginValue = axisRange.Begin + (axisRange.End - axisRange.Begin) * beginYFactor;
double endValue = axisRange.Begin + (axisRange.End - axisRange.Begin) * endYFactor;
if (m_RangeSelection.IsZoomIn())
{
m_Chart.Axis(StandardAxis.SecondaryY).PagingView.ZoomIn(new NRange1DD(beginValue, endValue), 0.0001);
}
else
{
m_Chart.Axis(StandardAxis.SecondaryY).PagingView.ZoomOut(new NRange1DD(beginValue, endValue), 0.0001);
}
}
}
}
The idea is simple:
1. Intercept the EndDrag event of the data zoom tool.
2. Compute the relative position of the zoomed range vs the axis range.
3. Compute the zoom range based on the secondary axis range using this relative position.
4. Zoom In / Zoom out.
Best Regards,
Nevron Support Team