简体   繁体   中英

Can't zoom in MSchart when adding the Y axis minimum / maximum

Whenever i'm adding the minimum / maximum to the Yaxis (chart1.ChartAreas[0].AxisY.Minimum & \\ chart1.ChartAreas[0].AxisY.Maximum) i'm loosing the ability of zooming in the chart.

Is there a way resolve this issue?

Does some one know if there is a limitations about zooming combined with min/max values?

Since there was no answer here, but a recent comment on the thread, and I found this thread while looking for an answer on this same question here's what I found was the problem in my case.

Check the chart area cursor's Interval and IntervalType values. Zooming may be enabled but your interval is large enough that with the min/max values you have the entire range of your chart is simply smaller than the interval you can select.

In my case I'm using DateTime for my axis value type and I with the 'Auto' IntervalType I couldn't zoom in on anything less than a day - and my chart only covered 10 hours and so zooming appeared to be disabled. I changed IntervalType from 'Auto' to 'Seconds' (leaving Interval at 1) and that lets me zoom into the detail level I need.

The following should enable zooming:

chart1.ChartAreas[0].CursorY.IsUserEnabled = true;
chart1.ChartAreas[0].CursorY.IsUserSelectionEnabled = true;
chart1.ChartAreas[0].AxisY.ScaleView.Zoomable = true;

Setting min/max on the axis seem to indeed prevent user-selected zoom. I'm not sure if you are trying to restrict the zooming or provide an initial zoom setting. For the later, do this instead of using min/ax on the axis:

chart1.ChartArea[0].AxisY.ScaleView.Zoom(min, max);

I can't verify the problem.
If I set the min/max I can still zoom the chart eg:

private void FillChart()
{
    var dt = new DataTable();
    dt.Columns.Add("X", typeof(double));
    dt.Columns.Add("Y", typeof(double));

    dt.Rows.Add(1, 3);
    dt.Rows.Add(2, 7);
    dt.Rows.Add(3, 2);
    dt.Rows.Add(4, 1);
    dt.Rows.Add(5, 5);
    dt.Rows.Add(6, 9);
    dt.Rows.Add(7, 0);

    this.chart1.Series.Clear();

    this.chart1.DataSource = dt;
    var series = this.chart1.Series.Add("MYSERIES");
    series.XValueMember = "X";
    series.YValueMembers = "Y";

    // set a custom minimum and maximum
    chart1.ChartAreas[0].AxisY.Minimum = -10;
    chart1.ChartAreas[0].AxisY.Maximum = 10;

    chart1.ChartAreas[0].CursorY.IsUserEnabled = true;
    chart1.ChartAreas[0].CursorY.IsUserSelectionEnabled = true;
    chart1.ChartAreas[0].AxisY.ScaleView.Zoomable = true; 
}

this works perfectly fine to me.

Did you do something different ?

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