简体   繁体   中英

How to zoom secondary y axis in mschart

I am making a plot which has both primary and secondary y axis but on zooming the chartarea only primary x axis and primary y axis are zooming and the scrollbar doesn't appear on the secondary Y Axis

        chrtarea.CursorX.IsUserEnabled = true;
        chrtarea.CursorX.IsUserSelectionEnabled = true;
        chrtarea.CursorY.IsUserEnabled = true;
        chrtarea.CursorY.IsUserSelectionEnabled = true;

        chrtarea.AxisX.ScaleView.Zoomable = true;
        chrtarea.AxisY.ScaleView.Zoomable = true;
        chrtarea.AxisY2.ScaleView.Zoomable = true;

Is there a problem with the code.Please tell how to do this.

I realise this question's old but I came up against this today.

The only way I could achieve a zoomable secondary Y axis was to change the max and min of the secondary Y axis to change when the axis view changes:

private void ChartMainAxisViewChanged(object sender, ViewEventArgs e)
{
    chartMain.ChartAreas[0].AxisY2.ScaleView.Position = chartMain.ChartAreas[0].AxisY.ScaleView.Position / 10.0;
    chartMain.ChartAreas[0].AxisY2.Minimum = chartMain.ChartAreas[0].AxisY.ScaleView.ViewMinimum / 10.0;
    chartMain.ChartAreas[0].AxisY2.Maximum = chartMain.ChartAreas[0].AxisY.ScaleView.ViewMaximum / 10.0;
    chartMain.ChartAreas[0].AxisY2.Interval = chartMain.ChartAreas[0].AxisY.Interval / 10.0;
    chartMain.ChartAreas[0].AxisY2.IntervalOffset = chartMain.ChartAreas[0].AxisY.IntervalOffset / 10.0;
}

This relies on having a scale ratio between the Y axis and the Y2 axis. Mine happened to be 10:1 so was easy to convert, but if yours is dynamic you'll need to calculate the ratio.

The last two lines also align the intervals, but you won't need this if you don't want aligned intervals.

I realise this question's old but I came up against this today.

You can switch CursorY to work with Secondary axis (AxisY2):

    chartarea.CursorY.AxisType = System.Windows.Forms.DataVisualization.Charting.AxisType.Secondary;

This will disable zooming on primary Y axis so if you wish to have zooming on both, stick to Erresen's answer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM