使用动态视图保存图表 [英] Saving charts with dynamic view
问题描述
在我的WinForms应用程序中,我必须显示线图。
我需要在我的应用程序中实现的一个功能是将图表保存到文件。保存图表并关闭应用程序后,可以打开保存的图表,用户可以放大/缩小图表进行分析。
大多数图表工具使用户可以将图表保存到像.png / .jpg等图像文件,这是静态的。
我想实现类似 Matlab的FIG文件 。有没有控制,已经这样做?
你有几个选择:
-
另存为
Jpg
或Png
尺寸足够大以缩放。为此,您可以放大图表然后再保存,然后再收缩。 / p> -
保存为
/ li>emf
格式之一。这保存了矢量格式,因此放大效果非常好,即使在大的缩放系数。 但,您需要一个特殊的查看器才能显示emf
格式或用于将转换为更标准的< c $ c> wmf 格式比图
创建的格式。很奇怪,MS图表
以.Net
格式保存无法读取: - (
-
保存到
XML
这意味着序列化,使用标准选项属性可序列化或不可序列化。请参见此代码直接从链接:string yourChartDataFile =d:\\\ \\ SavedChartData.xml;
private void saveButton_Click(object sender,EventArgs e)
{
chart1.Serializer.Save(yourChartDataFile);
}
private void loadButton_Click(object sender,EventArgs e)
{
chart1.Serializer.Load(yourChartDataFile);
}
要显示生成的文件,您需要另一个图表
control。显然。
我发现上面的两行工作相当好,没有添加褶边,但你可能需要或想保存的东西,如当前缩放状态或注释状态;我不知道什么是得到序列化的盒子和什么不..
In my WinForms application, I have to display line graphs.
One feature which I need to implement in my application is saving the chart to a file. Once the chart is saved and the application is closed, the saved chart can be opened and the user can zoom-in/zoom-out the chart for analysis.
Most charting tools enable user to save the chart to an image file like .png/.jpg etc., which are static.
I want to achieve something like Matlab's FIG file. Are there controls which already do this? Or if I have to implement it myself, what is the best approach?
You have a couple of options:
Save as
Jpg
orPng
in a size large enough to zoom in. To do so you would enlarge the chart before saving and then shrink it again.Save in one of the
emf
formats. This saves a vector format, so zooming in works very well, even at large zoom factors. However you need a special viewer to display theemf
formats or a tool to convert them to a more standardwmf
format than whatchart
creates. Rather strange that theMS chart
saves in a format.Net
can't read :-(Save to
XML
. This means serializing, either using the standard options or by marking certain properties as serializable or non-serializable. See here for more info! This code is straight from the link:string yourChartDataFile = "d:\\SavedChartData.xml"; private void saveButton_Click(object sender, EventArgs e) { chart1.Serializer.Save(yourChartDataFile); } private void loadButton_Click(object sender, EventArgs e) { chart1.Serializer.Load(yourChartDataFile); }
To display the resulting file you need another chart
control, obviously.
I found the two-liner above to work pretty well without adding frills, but you may need or want to save things like current zoom state or annotation states; I'm not sure just what does get serialized out of the box and what does not..
这篇关于使用动态视图保存图表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!