Profile Picture

zoom on primary and secondary axis in the same time

Posted By Daniel Csimszi 11 Years Ago
Author
Message
Daniel Csimszi
questionmark Posted 11 Years Ago
View Quick Profile
Forum Guru

Forum Guru (50 reputation)Forum Guru (50 reputation)Forum Guru (50 reputation)Forum Guru (50 reputation)Forum Guru (50 reputation)Forum Guru (50 reputation)Forum Guru (50 reputation)Forum Guru (50 reputation)Forum Guru (50 reputation)

Group: Forum Members
Last Active: 8 Years Ago
Posts: 61, Visits: 35
Hi,

I have a graph with 2 Y axis, one left one right and when I zoom I would like to zoom on both of them not just on the primary one. Could you tell me what I need to set for that?

Regards,
Daniel

Nevron Support
Posted 11 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: 1 days ago @ 1:54 AM
Posts: 3,054, Visits: 4,009

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



Daniel Csimszi
Posted 11 Years Ago
View Quick Profile
Forum Guru

Forum Guru (50 reputation)Forum Guru (50 reputation)Forum Guru (50 reputation)Forum Guru (50 reputation)Forum Guru (50 reputation)Forum Guru (50 reputation)Forum Guru (50 reputation)Forum Guru (50 reputation)Forum Guru (50 reputation)

Group: Forum Members
Last Active: 8 Years Ago
Posts: 61, Visits: 35
Thank you for the code,

It is half working. It zooms on the X axis for both but not on the Y axis. Is it working fine for you?

I have attached pictures about the graph in general and after zooming. As you can see it is zooms on the primary Y but no on the secondary.

Regards
Daniel

Attachments
generalGraph.png (156 views, 34.00 KB)
after zoom in.png (173 views, 38.00 KB)


Similar Topics


Reading This Topic