Use mouse wheel to operate zoom tool in the chart

Applies to: Nevron Chart for .NET

How to use mouse wheel to operate zoom tool in the chart?

The following example shows how to add mouse wheel Zoom Tool in Nevron Chart:


Figure1: sample bar chart


Figure2: bar chart after zooming with the mouse wheel

[C#]
using System;
using System.Drawing;
using System.Windows.Forms;
using Nevron.Chart;
using Nevron.Chart.WinForm;
using Nevron.GraphicsCore;
...
private void Form1_Load(object sender, EventArgs e)
{
    // add mouse wheel ZoomTool
    NZoomTool zt = new NZoomTool();
    zt.BeginDragMouseCommand = new NMouseCommand(MouseAction.Wheel, MouseButtons.Middle, 0);
    zt.ZoomStep = 16;
    nChartControl1.Controller.Tools.Add(zt);
     
    nChartControl1.Controller.Tools.Add(new NTrackballTool());
    nChartControl1.Settings.JitterMode = JitterMode.Enabled;
    nChartControl1.Settings.JitteringSteps = 8;
 
    NCartesianChart chart = (NCartesianChart)nChartControl1.Charts[0];
    chart.Axis(StandardAxis.Depth).Visible = false;
    chart.Dock = DockStyle.Fill;
    chart.DockMargins = new NMarginsL(5, 5, 5, 5);
 
    // add the chart to the currently selected objects:
    nChartControl1.Controller.Selection.Clear();
    nChartControl1.Controller.Selection.SelectedObjects.Add(chart);
 
    chart.Enable3D = true;
    chart.Depth = 10;
    chart.Projection.SetPredefinedProjection(PredefinedProjection.Perspective2);
    chart.LightModel.SetPredefinedLightModel(PredefinedLightModel.GlitterLeft);
 
    // configure the legend
    NLegend Legend = (NLegend)nChartControl1.Legends[0];
    Legend.Data.ExpandMode = LegendExpandMode.RowsFixed;
    Legend.Data.RowCount = 1;
    Legend.Dock = DockStyle.Top;
    Legend.DockMargins = new NMarginsL(5, 5, 5, 5);
    Legend.BoundsMode = BoundsMode.None;
 
    // add interlaced stripe to the Y axis
    NScaleStripStyle stripStyle = new NScaleStripStyle(new NColorFillStyle(Color.Beige), null, true, 0, 0, 1, 1);
    stripStyle.SetShowAtWall(ChartWallType.Back, true);
    stripStyle.SetShowAtWall(ChartWallType.Left, true);
    stripStyle.Interlaced = true;
    ((NStandardScaleConfigurator)chart.Axis(StandardAxis.PrimaryY).ScaleConfigurator).StripStyles.Add(stripStyle);
 
    // first cluster
    NBarSeries c1bar1 = (NBarSeries)chart.Series.Add(SeriesType.Bar);
    c1bar1.Name = "Series1";
    c1bar1.BarShape = BarShape.Cylinder;
    c1bar1.DataLabelStyle.Visible = false;
 
    NBarSeries c1bar2 = (NBarSeries)chart.Series.Add(SeriesType.Bar);
    c1bar2.Name = "Series2";
    c1bar2.BarShape = BarShape.Cylinder;
    c1bar2.DataLabelStyle.Visible = false;
 
    c1bar1.MultiBarMode = MultiBarMode.Series;
    c1bar2.MultiBarMode = MultiBarMode.Stacked; // stack on c1bar1
 
    // second cluster
    NBarSeries c2bar1 = (NBarSeries)chart.Series.Add(SeriesType.Bar);
    c2bar1.Name = "Series3";
    c2bar1.BarShape = BarShape.Cylinder;
    c2bar1.DataLabelStyle.Visible = false;
 
    NBarSeries c2bar2 = (NBarSeries)chart.Series.Add(SeriesType.Bar);
    c2bar2.Name = "Series4";
    c2bar2.BarShape = BarShape.Cylinder;
    c2bar2.DataLabelStyle.Visible = false;
 
    c2bar1.MultiBarMode = MultiBarMode.Clustered; // display next to c1bar1
    c2bar2.MultiBarMode = MultiBarMode.Stacked;   // stack on c2bar1
 
    // fill with random data
    Random rand = new Random();
    c1bar1.Values.FillRandomRange(rand, 5, 10, 100);
    c1bar2.Values.FillRandomRange(rand, 5, 10, 500);
    c2bar1.Values.FillRandomRange(rand, 5, 10, 500);
    c2bar2.Values.FillRandomRange(rand, 5, 10, 500);
 
    NStyleSheet styleSheet = NStyleSheet.CreatePredefinedStyleSheet(PredefinedStyleSheet.Autumn);
    styleSheet.Apply(nChartControl1.Document);
 
    nChartControl1.Refresh();
}

[VB.NET]
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports Nevron.Chart
Imports Nevron.Chart.WinForm
Imports Nevron.GraphicsCore
...
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 
    ' add mouse wheel ZoomTool
    Dim zt As New NZoomTool()
    zt.BeginDragMouseCommand = New NMouseCommand(MouseAction.Wheel, MouseButtons.Middle, 0)
    zt.ZoomStep = 8
    nChartControl1.Controller.Tools.Add(zt)
 
    nChartControl1.Controller.Tools.Add(New NTrackballTool())
    nChartControl1.Settings.JitterMode = JitterMode.Enabled
    nChartControl1.Settings.JitteringSteps = 8
 
    Dim chart As NCartesianChart = DirectCast(nChartControl1.Charts(0), NCartesianChart)
    chart.Axis(StandardAxis.Depth).Visible = False
    chart.Dock = DockStyle.Fill
    chart.DockMargins = New NMarginsL(5, 5, 5, 5)
 
    ' add the chart to the currently selected objects:
    NChartControl1.Controller.Selection.Clear()
    NChartControl1.Controller.Selection.SelectedObjects.Add(chart)
 
    chart.Enable3D = True
    chart.Depth = 10
    chart.Projection.SetPredefinedProjection(PredefinedProjection.Perspective2)
    chart.LightModel.SetPredefinedLightModel(PredefinedLightModel.GlitterLeft)
 
    ' configure the legend
    Dim Legend As NLegend = DirectCast(nChartControl1.Legends(0), NLegend)
    Legend.Data.ExpandMode = LegendExpandMode.RowsFixed
    Legend.Data.RowCount = 1
    Legend.Dock = DockStyle.Top
    Legend.DockMargins = New NMarginsL(5, 5, 5, 5)
    Legend.BoundsMode = BoundsMode.None
 
    ' add interlaced stripe to the Y axis
    Dim stripStyle As New NScaleStripStyle(New NColorFillStyle(Color.Beige), Nothing, True, 0, 0, 1, 1)
    stripStyle.SetShowAtWall(ChartWallType.Back, True)
    stripStyle.SetShowAtWall(ChartWallType.Left, True)
    stripStyle.Interlaced = True
    DirectCast(chart.Axis(StandardAxis.PrimaryY).ScaleConfigurator, NStandardScaleConfigurator).StripStyles.Add(stripStyle)
 
    ' first cluster
    Dim c1bar1 As NBarSeries = DirectCast(chart.Series.Add(SeriesType.Bar), NBarSeries)
    c1bar1.Name = "Series1"
    c1bar1.BarShape = BarShape.Cylinder
    c1bar1.DataLabelStyle.Visible = False
 
    Dim c1bar2 As NBarSeries = DirectCast(chart.Series.Add(SeriesType.Bar), NBarSeries)
    c1bar2.Name = "Series2"
    c1bar2.BarShape = BarShape.Cylinder
    c1bar2.DataLabelStyle.Visible = False
 
    c1bar1.MultiBarMode = MultiBarMode.Series
    c1bar2.MultiBarMode = MultiBarMode.Stacked  ' stack on c1bar1
 
    ' second cluster
    Dim c2bar1 As NBarSeries = DirectCast(chart.Series.Add(SeriesType.Bar), NBarSeries)
    c2bar1.Name = "Series3"
    c2bar1.BarShape = BarShape.Cylinder
    c2bar1.DataLabelStyle.Visible = False
 
    Dim c2bar2 As NBarSeries = DirectCast(chart.Series.Add(SeriesType.Bar), NBarSeries)
    c2bar2.Name = "Series4"
    c2bar2.BarShape = BarShape.Cylinder
    c2bar2.DataLabelStyle.Visible = False
 
    c2bar1.MultiBarMode = MultiBarMode.Clustered    ' display next to c1bar1
    c2bar2.MultiBarMode = MultiBarMode.Stacked      ' stack on c2bar1
 
    ' fill with random data
    Dim rand As New Random()
    c1bar1.Values.FillRandomRange(rand, 5, 10, 100)
    c1bar2.Values.FillRandomRange(rand, 5, 10, 500)
    c2bar1.Values.FillRandomRange(rand, 5, 10, 500)
    c2bar2.Values.FillRandomRange(rand, 5, 10, 500)
 
    Dim styleSheet As NStyleSheet = NStyleSheet.CreatePredefinedStyleSheet(PredefinedStyleSheet.Autumn)
    styleSheet.Apply(nChartControl1.Document)
 
    nChartControl1.Refresh()
End Sub

Article ID: 158, Created On: 12/15/2010, Modified: 3/29/2011