Generating and Saving ZedGraph plots without showing on forms

情到浓时终转凉″ 提交于 2019-12-05 17:42:53

问题


Is it possible to plot data on to a ZedGraph graph and save it as a file without showing / generating a graph that is visible to the user? I'm looking to process a lot of datasets and generate a graph and saving it to a file for viewing outside of the application.

If this can't be done, would it be possible show the graph on a hidden/minimized form, save the graph, close the window, and repeat for each graph?


回答1:


It is possible.

You create and manipulate the ZedGraph control as usual, but just don't add it to the Form.Controls list, for example, in the InitializeComponent() method, comment out something that looks like the below

this.Controls.Add(this.zedGraphControl);

There are a couple of ways to save the graph

  • If you want a SaveAs dialog to appear, call SaveAs() on the graph control.
  • If you don't want the dialog, you can write out the image using GetImage() on the MasterPane, and then save that:

    zedGraphControl.MasterPane.GetImage().Save("test.bmp");




回答2:


Here is a code snippet to create and save the Bitmaps without any WinForms infrastructure necessary:

var zedGraph = new ZedGraphControl();

// configure ZedGraphControl here

using (var g = zedGraph.CreateGraphics())
{
    zedGraph.MasterPane.ReSize(g, new RectangleF(0, 0, widthPx, heightPx));
}
zedGraph.MasterPane.GetImage().Save(Path.Combine(destinationDir, "test.bmp"));

This should even be able to run as service without any desktop. The only downside is that you need to reference System.Windows.Forms and System.Drawing to use it.



来源:https://stackoverflow.com/questions/6614801/generating-and-saving-zedgraph-plots-without-showing-on-forms

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