0

I am trying to use ZedGraph from MVC. Can I just generate an image result from ZedGraph and reference it from my view?

Curtis Yallop
  • 5,490
  • 3
  • 37
  • 27

2 Answers2

2

Ok, so I figured out how:

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 can be used from Windows Forms and as an ASP.NET web control. Using it from MVC is harder and this image method is the approach I came up with. Using ASP.NET web controls is possible in MVC, I think (does anyone know how?). If you have any other suggestions, please post them.

Curtis Yallop
  • 5,490
  • 3
  • 37
  • 27
0

Another example of how to do it.

J punto Marcos
  • 427
  • 1
  • 6
  • 24