Someone requested a quick snippet of how to get ZedGraph to work so here we go.
First off I use these 2 links for documentation The main wiki and the SourceForge project forum.
- Setup: Make sure you have the ZedGraph.dll and ZedGraph.Web.dll assemblies in your bin directory.
- Create a writeable directory in your web project for temp image creation, I called mine ~/Data/Charts
- Add a new .aspx page with and register the tagprefix for the web control by adding this line
<%
@ Register TagPrefix="zgw" Namespace="ZedGraph.Web" Assembly="ZedGraph.Web" %>
- Drop now drop a graph control on the page and make sure to use the same tag prefix. It should look something like this
<
zgw:ZEDGRAPHWEB id="zgChart" runat="server" Width="700" Height="400" RenderMode="RawImage" IsImageMap="false" RenderedImagePath="~/data/charts/" OnRenderGraph="zgChart_RenderGraph" />
- On Render Graph is where the magic happens. In your Code Behind Make sure you wire up your event like so: protected void zgChart_RenderGraph(Graphics g, MasterPane masterPane)
{
// Get the GraphPane so we can work with itGraphPane myPane = masterPane[0];
// Create a point pair list, there are many ways to populate the data besides this too.
PointPairList somePoints = new PointPairList();
// Add some points
somePoints.Add(0, 1);
somePoints.Add(1, 2);
somePoints.Add(2, 4);
somePoints.Add(3, 3);
// add the points to a curve on your pane.
BarItem myBar = myPane.AddBar("Series Title", somePoints, Color.Red);
// Finish up by telling the master pane to generate the axis.
masterPane.AxisChange(g);
}
-
Save and Run that should be it.