生成并保存 ZedGraph 绘图而不在表单上显示

发布于 2024-11-18 23:41:08 字数 148 浏览 4 评论 0原文

是否可以将数据绘制到 ZedGraph 图表上并将其保存为文件,而不显示/生成用户可见的图表?我希望处理大量数据集并生成图表并将其保存到文件中以便在应用程序外部查看。

如果无法做到这一点,是否可以在隐藏/最小化表单上显示图形,保存图形,关闭窗口,然后对每个图形重复?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

隔岸观火 2024-11-25 23:41:08

这是可能的。

您像往常一样创建和操作 ZedGraph 控件,但只是不要将其添加到 Form.Controls 列表中,例如,在 InitializeComponent() 方法中,注释掉如下所示

this.Controls.Add(this.zedGraphControl);

有多种方法可以保存图形

  • 如果您希望显示 SaveAs 对话框,请在图形控件上调用 SaveAs()
  • 如果您不需要该对话框,可以在 MasterPane 上使用 GetImage() 写出图像,然后保存:

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

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

樱&纷飞 2024-11-25 23:41:08

下面是一个代码片段,用于创建和保存位图,无需任何 WinForms 基础设施:

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

这甚至应该能够在没有任何桌面的情况下作为服务运行。唯一的缺点是您需要引用 System.Windows.Forms 和 System.Drawing 才能使用它。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文