Guys,
I'm trying to build zoom & scroll on mouse left button and wheel similar to what Goolge Finance's chart does. I've intercepted the mouse events on the chart control and redirected them to the NAxisScroll tool hoping that it will do the heavy lift me but it doesn't seem to work.
Any hint is highly appreciated.
Find below the code snippet that supposed to do it.
Thanks,
Plamen
NAxisScrollTool axisScrollTool = new NAxisScrollTool();
private void Form3_Load(object sender, EventArgs e)
{
NCartesianChart chart = (NCartesianChart)nChartControl1.Charts[0];
chart.Dock = DockStyle.Fill;
NLineSeries line = (NLineSeries)chart.Series.Add(SeriesType.Line);
line.UseXValues = true;
line.DataLabelStyle = new NDataLabelStyle();
NDateTimeAxisPagingView dateTimePagingView = new NDateTimeAxisPagingView(DateTime.Now.AddMonths(-1), new NDateTimeSpan(1, NDateTimeUnit.Month));
dateTimePagingView.Enabled = true;
NAxis axis = chart.Axis(StandardAxis.PrimaryX);
axis.PagingView = dateTimePagingView;
NValueTimelineScaleConfigurator timelineScale = new NValueTimelineScaleConfigurator();
axis.ScaleConfigurator = timelineScale;
axis.View = new NRangeAxisView(new NRange1DD(DateTime.Now.AddYears(-1).ToOADate(), DateTime.Now.ToOADate()));
axis.ScrollBar.Visible = true;
nChartControl1.Controller.Tools.Add(axisScrollTool);
nChartControl1.MouseDown += new MouseEventHandler(nChartControl1_MouseDown);
nChartControl1.MouseUp += new MouseEventHandler(nChartControl1_MouseUp);
nChartControl1.MouseMove += new MouseEventHandler(nChartControl1_MouseMove);
Random random = new Random();
for (DateTime dt = DateTime.Now; dt > DateTime.Now.AddYears(-1); dt = dt.AddDays(-1))
{
line.XValues.Add(dt);
line.Values.Add(random.Next(100));
}
}
void nChartControl1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
axisScrollTool.OnMouseMove(sender, e);
}
}
void nChartControl1_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
axisScrollTool.OnMouseUp(sender, e);
}
}
void nChartControl1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
axisScrollTool.OnMouseDown(sender, e);
}
}