使用动态视图保存图表 [英] Saving charts with dynamic view

查看:159
本文介绍了使用动态视图保存图表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的WinForms应用程序中,我必须显示线图。



我需要在我的应用程序中实现的一个功能是将图表保存到文件。保存图表并关闭应用程序后,可以打开保存的图表,用户可以放大/缩小图表进行分析。



大多数图表工具使用户可以将图表保存到像.png / .jpg等图像文件,这是静态的。



我想实现类似 Matlab的FIG文件 。有没有控制,已经这样做?

解决方案

你有几个选择:





要显示生成的文件,您需要另一个图表 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 or Png 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 the emf formats or a tool to convert them to a more standard wmf format than what chart creates. Rather strange that the MS 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆