MSChart - 在 X 轴缩放上自动缩放 Y 轴
我正在使用 MSChart,我想在 X 轴上启用缩放,一旦缩放,我希望 Y 轴自动缩放到适合数据可见的范围。
任何有关问题的帮助将不胜感激!
谢谢
I'm using MSChart and I want to enable zoom on the X Axis and once this is zoomed I want the Y Axis to auto zoom into a range appropriate for the data viewable.
Any assistance with the problem would be greatly appreciated!
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我花了很长时间寻找解决方案。我发现这很有用。订阅 AxisValueChanged 事件并使用 ScaleView 修改视图。
I was searching for a solution for a long time. I found this useful. Subscribe to AxisValueChanged event and use ScaleView to modify the view.
MSChart 无法自动完成您想要执行的缩放操作。从用户那里检索到“放大”X 值范围后,您需要编写更多代码来适当重置 Y 轴缩放。
如果您使用的是线型数据系列并且该系列的源数据存储为 SortedList,则此方法最容易实现。
一旦您使用类似上面的代码来获取 minY 和 maxY,您就可以使用这些值来重置 ChartArea 上的最小和最大 Y 轴值:
The kind of zooming that you want to do cannot be automatically accomplished by MSChart. Once you have retrieved the 'Zoom-In' X-value range from the user, you need to write a little more code to reset the Y-axis scaling appropriately.
This works most easily if you are using a Line style of data series and your source data for that series is stored as a SortedList.
Once you have used something like the code above to get your minY and maxY, you can then use those values to reset the min and max Y-axis values on the ChartArea:
Microsoft 已提供全系列示例供下载。在示例应用程序中,有一个名为 Scrollable Appearance 的应用程序,它似乎可以满足您的需求。
可滚动外观 http://img502.imageshack.us/img502/5172/zoomablechart.png< /a>
用户可以选择图表的区域,图表将会放大。他们还可以使用滚动条四处移动。
下载中包含 C# 示例代码。
Microsoft have made available a whole range of samples for download. In the sample application there is one called Scrollable Appearance that seems to do what you want.
Scrollable Appearance http://img502.imageshack.us/img502/5172/zoomablechart.png
The user can select and area of the graph and it will zoom in. They can also move around using the scroll bars.
C# Sample code is included with the download.