简体   繁体   English

如何在mschart中缩放次要y轴

[英]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 我正在制作一个同时具有主要和次要y轴的图,但是在缩放图表区域时,只有主要x轴和主要y轴正在缩放,并且滚动条没有出现在次要Y轴上

        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: 我可以实现可缩放的辅助Y轴的唯一方法是更改​​辅助Y轴的最大值和最小值以在轴视图更改时更改:

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. 这取决于在Y轴和Y2轴之间具有缩放比例。 Mine happened to be 10:1 so was easy to convert, but if yours is dynamic you'll need to calculate the ratio. 我的碰巧是10:1,所以很容易转换,但是如果您的动态,则需要计算比率。

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): 您可以切换CursorY以与辅助轴(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 这将禁用在主要Y轴上的缩放,因此,如果您希望同时缩放两个,请遵循Erresen的回答

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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