c# - 你如何使用 MSChart for .Net 中的 Zooming UI

标签 c# .net visual-studio-2012 mschart

我刚刚开始考虑将 .Net 3.5 的 MSChart 控件用于即将开始的项目。该项目的要求之一是用户能够在必要时放大图表以更清楚地查看小数据点。

我看了很多教程,要么没有提到缩放,要么只是提供了一些关于如何启用它的简短信息,并且似乎假设使用它是如此明显以至于不需要解释。

我创建了一个快速测试项目,将控件添加到窗体中,然后在默认系列中添加了几个点。然后,我进入 ChartAreas 集合并确保在默认的 ChartArea 中,所有 Axis 成员的 ScaleView 属性中的 Zoomable 属性设置为 True。

当我运行该应用程序时,我的图表显示全部正确,但我无法理解任何放大它的方法。我试过点击它、双击、滚轮、ctrl-滚轮、ctrl-+ 和许多其他东西。

我显然遗漏了一些东西。谁能告诉我我做错了什么,我如何启用缩放 UI,以及我实际如何使用缩放 UI?

我在 Windows 7 上,使用 VS2012。

谢谢。

[编辑:修复了标题中愚蠢的拼写错误]

最佳答案

执行类似下面的操作应该允许您使用鼠标左键单击并拖动来缩放:

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);
    }
}

this.cwSubplot 是您希望缩放工作的 Chart 对象。

关于c# - 你如何使用 MSChart for .Net 中的 Zooming UI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18892201/

相关文章:

c# - 使用 RSS 提要 XML 并显示信息

.net - 我可以从 .NET 4.0 项目中引用 .NET 4.5 项目吗?

c# - OutOfMemoryException @WriteableBitmap @后台代理

c# - Seemann 依赖注入(inject), "Three Calls Pattern"与服务定位器反模式

C#覆盖关键字

c++ - 如何在 Visual Studio 2012 中包含库?

c++ - 项目中的链接错误

c# - TextWrapping、TextTrimming、居中对齐和垂直拉伸(stretch)

.net - "Put N Queens",是否可以在 N = 20 的情况下在可接受的时间内运行?

c# - 我的 Windows 窗体项目上的 Media Player 经典库