How do you use the Zooming UI in MSChart for .Net

自古美人都是妖i 提交于 2019-12-10 11:24:11

问题


I have just started looking at potentially using the MSChart control for .Net 3.5 for a project that will be starting shortly. One of the requirements of the project is that the users be able to zoom into the charts to see small data points more clearly when necessary.

I have looked at a number of tutorials and the either do not mention zooming, or just give a brief bit of information about how to enable it and seem to assume that using it is so obvious that it requires no explanation.

I created a quick test project, added the control to the form, and then added a few Points to the default Series. I then went into the ChartAreas collection and made sure that in the default ChartArea, the Zoomable property was set to True in the ScaleView property of all of the Axis members.

When I run the application my chart shows all correctly, but I cannot fathom any way to zoom into it. I have tried clicking on it, double clicking, the scroll wheel, ctrl-scroll wheel, ctrl-+, and many other things.

I am obviously missing something. Could someone please tell me what I am doing wrong, how I enable the zooming UI, and how I actually use the zooming UI?

I am on Windows 7, using VS2012.

Thank you.

[edit: fixed idiotic spelling error in title]


回答1:


Doing something like the following should allow you to Zoom using the Mouse Left Click and Drag:

private void ZoomToggle(bool Enabled)
{
    // Enable range selection and zooming end user interface
    this.cwSubplot.ChartAreas(0).CursorX.IsUserEnabled = Enabled;
    this.cwSubplot.ChartAreas(0).CursorX.IsUserSelectionEnabled = Enabled;
    this.cwSubplot.ChartAreas(0).CursorX.Interval = 0;
    this.cwSubplot.ChartAreas(0).AxisX.ScaleView.Zoomable = Enabled;
    this.cwSubplot.ChartAreas(0).AxisX.ScrollBar.IsPositionedInside = true;
    this.cwSubplot.ChartAreas(0).AxisX.ScrollBar.ButtonStyle = System.Windows.Forms.DataVisualization.Charting.ScrollBarButtonStyles.SmallScroll;
    this.cwSubplot.ChartAreas(0).AxisX.ScaleView.SmallScrollMinSize = 0;

    this.cwSubplot.ChartAreas(0).CursorY.IsUserEnabled = Enabled;
    this.cwSubplot.ChartAreas(0).CursorY.IsUserSelectionEnabled = Enabled;
    this.cwSubplot.ChartAreas(0).CursorY.Interval = 0;
    this.cwSubplot.ChartAreas(0).AxisY.ScaleView.Zoomable = Enabled;
    this.cwSubplot.ChartAreas(0).AxisY.ScrollBar.IsPositionedInside = true;
    this.cwSubplot.ChartAreas(0).AxisY.ScrollBar.ButtonStyle = System.Windows.Forms.DataVisualization.Charting.ScrollBarButtonStyles.SmallScroll;
    this.cwSubplot.ChartAreas(0).AxisY.ScaleView.SmallScrollMinSize = 0;
    if (Enabled == false) {
        //Remove the cursor lines
        this.cwSubplot.ChartAreas(0).CursorX.SetCursorPosition(double.NaN);
        this.cwSubplot.ChartAreas(0).CursorY.SetCursorPosition(double.NaN);
    }
}

Where this.cwSubplot is the Chart object you want zooming to work on.



来源:https://stackoverflow.com/questions/18892201/how-do-you-use-the-zooming-ui-in-mschart-for-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!