OnDataZoom event for NChartControl


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

By Manal Goyal - 6 Years Ago
Hi Team,
I am using zoom for both WPF(NChartControl) and Web application(NThinChartControl). Initially I have scale breaks in my chart with zooming enabled, as soon as user zoom into the chart I want to clear scale breaks, I found a way to do that for NThinChartControl in Nevron.Chart.ThinWeb.NDataZoomTool, I set DataZoomCallback and then in OnDataZoom method I have logic to clear scale breaks.

I wanted to know is it possible to have this functionality in NChartControl? Is there any other workaround to achieve what I want to achieve?

Thanks and regards
Manal
By Nevron Support - 6 Years Ago
Hi Manal,
You can achieve that by intercepting the EndDrag event - the following code shows how to do that:

  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(30);
   bar.Values.Add(40);

   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)
  {
   MessageBox.Show("End drag");
  }

Hope this helps - let us know if you have any questions or meet any problems.
By Manal Goyal - 6 Years Ago
Thanks, that worked for me,

I have one more question on this, when I try to zoom out of the chart I have to do it multiple times to get back to the orignal chart, is there any way I can zoom out on a single right to left mouse motion?
By Nevron Support - 6 Years Ago
Hi Manal,

Yes you need to set the ZoomOutResetAxis to false- for example:

NRangeSelection rangeSelection = new NRangeSelection();
rangeSelection.ZoomOutResetsAxis = true;
chart.RangeSelections.Add(rangeSelection);

Let us know if you meet any problems or have any questions.
By Manal Goyal - 6 Years Ago
Hi Team,

Thank you for the solution, it worked for me. However I have one more thing to ask, while dragiing the mouse to zoom in, it shows a horizontal black line for the range on the axis that will be selected to zoom in. Is there any way I can get the pan like zooming that I have for web forms application.

Thanks
Manla
By Nevron Support - 6 Years Ago
Hi Manal,

We're not sure what is the problem - do you want to disable the range selection border? In this case you can turn off the ZoomInBorderStyle and ZoomOutBorderStyle:

   NDataZoomTool dataZoomTool = new NDataZoomTool();
   dataZoomTool.ZoomInBorderStyle.Width = new NLength(0);
   dataZoomTool.ZoomOutBorderStyle.Width = new NLength(0);
   nChartControl1.Controller.Tools.Add(dataZoomTool);

If that is not problem - can you send a screenshot of the problem along with the code that configures the control?

By Manal Goyal - 6 Years Ago
Please find attached snaps describing my problem.

In the sample nevron app I found this nice rectangle that clearly shows the area I want to zoom in, which looks very good. I want something like that.




This is the code snippet that I have in my application to achieve zooming.


    var chartPlotter = new ChartPlotter(new NevronVisualEntityFactory());
    IScene scene = chartPlotter.CreateMeasuredDeviationsChart(deviations, measurementTime, correctionEvents);

    scene.Render(nChartControl);

    var chart = nChartControl.Charts[0];

    NRangeSelection rangeSelection = new NRangeSelection();
    rangeSelection.VerticalValueSnapper = new NAxisRulerMinMaxSnapper();
    ((NCartesianChart)chart).RangeSelections.Add(rangeSelection);
    
    nChartControl.Controller.Tools.Add(new NPanelSelectorTool());
    nChartControl.Controller.Tools.Add(new NAxisScrollTool());
    nChartControl.Controller.Tools.Add(new NDataZoomTool());
    nChartControl.Controller.Tools.Add(new NDataPanTool());
By Nevron Support - 6 Years Ago
Hi Manal,
This code looks ok however it is unclear whether you use a single chart panel or multiple chart panels. In case you use a single chart panel with many docked Y axes you also need to specify the vertical axis for the range selection. For example:
rangeSelection.VerticalAxisId = someAxis.AxisId;
You can also send us a snapshot of the chart state:
nChartControl1.Serializer.SaveControlStateToFile("c:\\temp\\chartstate.xml", Nevron.Serialization.PersistencyFormat.CustomXML, null);
(you need to send us the generaed chartstate.xml file) so that we can investigate further.

Hope this helps - let us know if you meet any problems or have any questions.
By Manal Goyal - 6 Years Ago
Hi,

I have used a similar way that is present in exmaples->RealTime->RealTimeLine
like this:
NAxis axis1 = chart.Axis(StandardAxis.PrimaryY);
ConfigureAxis(axis1, 0, 30, "Signal 1");

NAxis axis2 = chart.Axis(StandardAxis.SecondaryY);
ConfigureAxis(axis2, 35, 65, "Signal 2");

NAxis axis3 = ((NCartesianAxisCollection)chart.Axes).AddCustomAxis(AxisOrientation.Vertical, AxisDockZone.FrontRight);
ConfigureAxis(axis3, 70, 100, "Signal 3");

I want the range selection box to appear across whole y axis.

I tried what you suggested like:
    NRangeSelection rangeSelection = new NRangeSelection();
    rangeSelection.VerticalValueSnapper = new NAxisRulerMinMaxSnapper();
    ((NCartesianChart)chart).RangeSelections.Add(rangeSelection);
    rangeSelection.VerticalAxisId = 1;

but that did not make any difference.
By Nevron Support - 6 Years Ago
Hi Manal,
We were not able to replicate the problem - we tested with the following code:
using Nevron.Chart;
using Nevron.Chart.Windows;
using System;
using System.Windows.Forms;

namespace WindowsFormsApp2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}


private void Form1_Load(object sender, EventArgs e)
{
NCartesianChart chart = (NCartesianChart)nChartControl1.Charts[0];
chart.Axis(StandardAxis.PrimaryX).ScrollBar.Visible = true;

NAxis axis1 = chart.Axis(StandardAxis.PrimaryY);
ConfigureAxis(axis1, 0, 30, "Signal 1");

NAxis axis2 = chart.Axis(StandardAxis.SecondaryY);
axis2.Visible = true;
ConfigureAxis(axis2, 35, 65, "Signal 2");

NAxis axis3 = ((NCartesianAxisCollection)chart.Axes).AddCustomAxis(AxisOrientation.Vertical, AxisDockZone.FrontRight);
ConfigureAxis(axis3, 70, 100, "Signal 3");

NRangeSelection rangeSelection = new NRangeSelection();
rangeSelection.VerticalValueSnapper = new NAxisRulerMinMaxSnapper();
rangeSelection.VerticalAxisId = axis2.AxisId;
chart.RangeSelections.Add(rangeSelection);

NLineSeries line1 = new NLineSeries();
FillData(line1);
chart.Series.Add(line1);

NLineSeries line2 = new NLineSeries();
FillData(line2);
chart.Series.Add(line2);
line2.DisplayOnAxis(StandardAxis.PrimaryY, false);
line2.DisplayOnAxis(axis2.AxisId, true);

NLineSeries line3 = new NLineSeries();
FillData(line3);
chart.Series.Add(line3);
line3.DisplayOnAxis(StandardAxis.PrimaryY, false);
line3.DisplayOnAxis(axis3.AxisId, true);

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

}

private void FillData(NLineSeries line)
{
Random rand = new Random();
line.DataLabelStyle.Visible = false;
for (int i = 0; i < 100; i++)
{
line.Values.Add(rand.Next(100));
}
}

private void ConfigureAxis(NAxis axis, float beginPercent, float endPercent, string text)
{
axis.Anchor = new NDockAxisAnchor(AxisDockZone.FrontLeft, false, beginPercent, endPercent);

NLinearScaleConfigurator scale = new NLinearScaleConfigurator();
scale.Title.Text = text;
axis.ScaleConfigurator = scale;
}
}
}

and the control was working properly. Can you sends us a small application that replicates this problem?
By Manal Goyal - 6 Years Ago
Hi Team,

where should I send the sample application?
By Nevron Support - 6 Years Ago
Hi Manal,

Please send the application to support@nevron.com. Thank you.