Opensource C# Graph Plot Library – ZedGraph

Update: Check out Zedgraph C# Graph Plot Example Application , I have an example ZedGraph Application (with sourcecode) to draw Line Plot, Bar Graph and Pie Chart.

Update 2: Check out ZedGraph C# Graph Data Export to CSV Using a Custom Context Menu , It has code to make a custom context menu item and also export the graph plot data as CSV.

ZedGraph C# Graph Library

I was searching for an opensource(hence free) Graph plotting library in C# (or VB.NET), so that it could be used in our IN-Motion addin for Autodesk Inventor. After some googling, I found 2 suitable open source libraries namely ZedGraph and NPlot. When both websites(read wiki) were compared, I found ZedGraph recently updated and also had great documentation to take off immediately. I readily downloaded the latest version of ZedGraph dll from its SourceForge project and followed the instructions on ZedGraph wiki.

Within no time, I was ready with ZedGraphTest example, whose screenshot is above. It is so simple that, without even exploring, I could accomplish basic graph plotting. Some of the plus points I see in ZedGraph are:

  • Not much tweaking of source-code is required for basic tasks.
  • All the plot elements (line, curve, panel, axes, plot-markers etc) can be set different colors. Even gradients can be set to have crazy as well as good looking Graphs
  • Different types of graphs (line,bar,pie etc) are possible with ease.
  • Using left click on the plot panel, the graph can be zoomed
  • Middle button can be used to pan the plot
  • Upon right click over the plot, a context menu appears which, out of the box has a lot of useful features such as saving the image, toggle the on-hover highligthing etc
The code for my ZedGraphTest is below. I have changed only CreateGraph() method, and the remaining code is same as in the example.
[sourcecode language=’c#’]
private void CreateGraph(ZedGraphControl zgc)
{
GraphPane myPane = zgc.GraphPane;

// Set the titles and axis labels
myPane.Title.Text = “ZedGraph Test”;
myPane.XAxis.Title.Text = “theta (angle)”;
myPane.YAxis.Title.Text = “Sin (theta)”;

// Make up some data points from the Sine function
PointPairList _list1 = new PointPairList();
for (double x = 0; x <= 360; x += 10) { double y = Math.Sin(x * Math.PI / 180.0); _list1.Add(x, y); } // Generate a blue curve with Plus symbols, LineItem _myCurve1 = myPane.AddCurve("Sin (theta)", _list1, Color.Blue,SymbolType.Plus); // Fill the pane background with a color gradient myPane.Fill = new Fill(Color.White, Color.FromArgb(220, 220, 255), 45F); //Make the MajorGrids of Axes visible myPane.XAxis.MajorGrid.IsVisible = true; myPane.YAxis.MajorGrid.IsVisible = true; // Calculate the Axis Scale Ranges zgc.AxisChange(); } [/sourcecode] So far, this library has been a boon to me as I dont have to reinvent the wheel again. Thanks a ton to ZedGraph guys 🙂

5 thoughts on “Opensource C# Graph Plot Library – ZedGraph

  1. Thanks for the review, I couldn’t decide which library to try but this article has been informative. Will be giving ZedGraph a shot.

  2. Pingback: Zedgraph C# Graph Plot Example Application | SmallGuru

  3. Pingback: ZedGraph C# Graph Data Export to CSV using a custom Context Menu | SmallGuru

  4. please provide me sample web application ,which is used to create the Zedgraph with the button event not with the zedwebcontrol event handler

  5. does anyone know how can I write a code for EEG. when I connect the EEG boards to pc and run the code I have to get the signals

Leave a Reply

Your email address will not be published. Required fields are marked *