Data zoom with mouse wheel does not work.


https://www.nevron.com/Forum/Topic12755.aspx
Print Topic | Close Window

By cho seongho - 5 Years Ago

I checked the "Wheel Zoom" check box in the "Data Zoom Tool" of the sample provided by your company and tried to operate the mouse wheel but it does not work. And I applied the following code to my source code, but it also does not work.


NDataTool dataZoomTool = new NDataZoomTool();
dataZoomTool.WheelZoomAtMouse = true;
dataZoomTool.BeginDragMouseCommand = new NMouseCommand(MouseAction.Wheel, MouseButton.Middle, 0);
nChartControl1.Controller.Tools.Add(dataZoomTool);


By Nevron Support - 5 Years Ago
Hi Cho,
In order to have the wheel zoom feature working you need to have a range selection object and selected chart - for example:
   NCartesianChart chart = (NCartesianChart)nChartControl1.Charts[0];
    chart.RangeSelections.Add(new NRangeSelection());

    NLineSeries line = new NLineSeries();
    chart.Series.Add(line);
    Random rand = new Random();

    line.UseXValues = true;
    line.DataLabelStyle.Visible = false;

    for (int i = 0; i < 40; i++)
    {
      line.Values.Add(rand.Next(100));
      line.XValues.Add(i);
    }

    chart.Axis(StandardAxis.PrimaryX).View = new NRangeAxisView(new NRange1DD(0, 100), true, true);
    chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = new NLinearScaleConfigurator();

    NDataZoomTool dataZoomTool = new NDataZoomTool();
    dataZoomTool.WheelZoomAtMouse = true;
    dataZoomTool.BeginDragMouseCommand = new NMouseCommand(MouseAction.Wheel, MouseButton.None, 0);
    nChartControl1.Controller.Tools.Add(dataZoomTool);

    nChartControl1.Controller.Selection.Add(chart);
Now when you press the Ctrl button + the mouse wheel you'll be able to zoom in / out at the current mouse position.
Hope this helps - let us know if you have any questions or meet any problems.
By cho seongho - 5 Years Ago
Thank you for answer.
I have confirmed that it works well by applying the answer.
In addition, can I zoom in / out for each axis using the mouse wheel?

For example
<shift + wheel>: Only the X axis is Zoom
<ctrl + wheel>: Only the Y axis is Zoom

Please answer this question.
By Nevron Support - 5 Years Ago
Hi Cho,
Yes you can disable vertical zooming using:
rangeSelection.VerticalValueSnapper = new NAxisRulerMinMaxSnapper();
similarly for the x axis:
rangeSelection.HorizontalValueSnapper = new NAxisRulerMinMaxSnapper();

so the code becomes:
   NCartesianChart chart = (NCartesianChart)nChartControl1.Charts[0];
    NRangeSelection rangeSelection = new NRangeSelection();
    rangeSelection.VerticalValueSnapper = new NAxisRulerMinMaxSnapper();
    chart.RangeSelections.Add(rangeSelection);

    NLineSeries line = new NLineSeries();
    chart.Series.Add(line);
    Random rand = new Random();

    line.UseXValues = true;
    line.DataLabelStyle.Visible = false;

    for (int i = 0; i < 40; i++)
    {
      line.Values.Add(rand.Next(100));
      line.XValues.Add(i);
    }

    chart.Axis(StandardAxis.PrimaryX).View = new NRangeAxisView(new NRange1DD(0, 100), true, true);
    chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = new NLinearScaleConfigurator();

    NDataZoomTool dataZoomTool = new NDataZoomTool();
    dataZoomTool.WheelZoomAtMouse = true;
    dataZoomTool.BeginDragMouseCommand = new NMouseCommand(MouseAction.Wheel, MouseButton.None, 0);
    nChartControl1.Controller.Tools.Add(dataZoomTool);

    nChartControl1.Controller.Selection.Add(chart);
There is no way to have two data zoom tools that zoom differently - you need to switch between a configuration that has range selection that zooms only horizontally or vice versa. Let us know if you have any questions.