0

我正在尝试使用 MVC 中的 ZedGraph。我可以从 ZedGraph 生成图像结果并从我的视图中引用它吗?

4

2 回答 2

2

好的,所以我想出了如何:

public FileContentResult Graph()
{
    var web = new ZedGraphWeb();
    web.Height = 450;
    web.Width = 800;
    web.RenderGraph += (w, g, masterPane) =>
                       {
                           GraphPane myPane = masterPane[0];
                           var xData = new double[] { 1, 2, 3 };
                           var yData = new double[] { 10, 60, 50 };
                           myPane.AddCurve("Allocated", xData, yData, Color.Black);
                       };
    var ms = new MemoryStream();
    web.CreateGraph(ms, ImageFormat.Png);
    return new FileContentResult(ms.ToArray(), "image/png");
}

<img src="@Url.Action("Graph")"/>

ZedGraph 可以在 Windows 窗体中使用,也可以用作 ASP.NET Web 控件。从 MVC 中使用它更难,这种图像方法是我想出的方法。我认为在 MVC 中使用 ASP.NET Web 控件是可能的(有人知道怎么做吗?)。如果您有任何其他建议,请发布。

于 2012-05-17T17:11:05.557 回答
0

如何做到这一点的另一个例子。

于 2012-11-15T09:28:02.270 回答