{"id":33,"date":"2008-12-18T01:16:22","date_gmt":"2008-12-17T19:46:22","guid":{"rendered":"http:\/\/www.smallguru.com\/?p=32"},"modified":"2008-12-18T01:16:22","modified_gmt":"2008-12-17T19:46:22","slug":"opensource-c-graph-plot-library-zedgraph","status":"publish","type":"post","link":"https:\/\/www.ar-cad.com\/smallguru\/2008\/12\/opensource-c-graph-plot-library-zedgraph\/","title":{"rendered":"Opensource C# Graph Plot Library &#8211; ZedGraph"},"content":{"rendered":"<p><strong>Update: Check out <a title=\"Permanent Link to Zedgraph C# Graph Plot Example Application\" rel=\"bookmark\" href=\"http:\/\/www.smallguru.com\/2009\/01\/zedgraph-csharp-graph-plot-example-application\/\">Zedgraph C# Graph Plot Example Application<\/a> , I have an example ZedGraph Application (with sourcecode) to draw Line Plot, Bar Graph and Pie Chart.<\/strong><\/p>\n<p><strong>Update 2: Check out <a title=\"Permanent Link to ZedGraph C# Graph Data Export to CSV Using a Custom Context Menu\" rel=\"bookmark\" href=\"http:\/\/www.smallguru.com\/2009\/06\/zedgraph-csharp-graph-data-export-to-cs\/\">ZedGraph C# Graph Data Export to CSV Using a Custom Context Menu<\/a> , It has code to make a custom context menu item and also export the graph plot data as CSV.<\/strong><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.smallguru.com\/wordpress\/wp-content\/upload\/zedGraphTest.png\" alt=\"ZedGraph C# Graph Library\" width=\"500\" height=\"372\" \/><\/p>\n<p>I was searching for an opensource(hence free) Graph plotting library in C# (or VB.NET), so that it could be used in our <a href=\"http:\/\/www.smallguru.com\/2008\/12\/in-motion-motion-simulation-addin\/\" target=\"_blank\">IN-Motion addin for Autodesk Inventor<\/a>. After some googling, I found 2 suitable open source libraries namely <a href=\"http:\/\/www.zedgraph.org\/\" target=\"_blank\">ZedGraph<\/a> and <a href=\"http:\/\/www.netcontrols.org\/nplot\/wiki\/\">NPlot<\/a>. 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 <a href=\"http:\/\/sourceforge.net\/projects\/zedgraph\/\" target=\"_blank\">ZedGraph dll from its SourceForge project<\/a> and followed the <a href=\"http:\/\/www.zedgraph.org\/wiki\/index.php?title=CSharp_Reference_Code_for_Sample_Charts\" target=\"_blank\">instructions on ZedGraph wiki<\/a>.<\/p>\n<p>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:<\/p>\n<ul>\n<li>Not much tweaking of source-code is required for basic tasks.<\/li>\n<li>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<\/li>\n<li>Different types of graphs (line,bar,pie etc) are possible with ease.<\/li>\n<li>Using left click on the plot panel, the graph can be zoomed<\/li>\n<li>Middle button can be used to pan the plot<\/li>\n<li>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<\/li>\n<\/ul>\n<div>The code for my ZedGraphTest is below. I have changed only CreateGraph() method, and the remaining code is same as in the <a href=\"http:\/\/zedgraph.org\/wiki\/index.php?title=CSharp_Reference_Code_for_Sample_Charts\" target=\"_blank\">example<\/a>.<br \/>\n[sourcecode language=&#8217;c#&#8217;]<br \/>\nprivate void CreateGraph(ZedGraphControl zgc)<br \/>\n{<br \/>\nGraphPane myPane = zgc.GraphPane;<\/p>\n<p>\/\/ Set the titles and axis labels<br \/>\nmyPane.Title.Text = &#8220;ZedGraph Test&#8221;;<br \/>\nmyPane.XAxis.Title.Text = &#8220;theta (angle)&#8221;;<br \/>\nmyPane.YAxis.Title.Text = &#8220;Sin (theta)&#8221;;<\/p>\n<p>\/\/ Make up some data points from the Sine function<br \/>\nPointPairList _list1 = new PointPairList();<br \/>\nfor (double x = 0; x <= 360; x += 10)\n{\ndouble y = Math.Sin(x * Math.PI \/ 180.0);\n_list1.Add(x, y);\n}\n\/\/ Generate a blue curve with Plus symbols,\nLineItem _myCurve1 =\nmyPane.AddCurve(\"Sin (theta)\", _list1, Color.Blue,SymbolType.Plus);\n\n\/\/ Fill the pane background with a color gradient\nmyPane.Fill = new Fill(Color.White, Color.FromArgb(220, 220, 255), 45F);\n\n\/\/Make the MajorGrids of Axes visible\nmyPane.XAxis.MajorGrid.IsVisible = true;\nmyPane.YAxis.MajorGrid.IsVisible = true;\n\n\/\/ Calculate the Axis Scale Ranges\nzgc.AxisChange();\n}\n[\/sourcecode]\n\nSo far, this library has been a boon to me as I dont have to reinvent the wheel again. Thanks a ton to ZedGraph guys :)\n\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>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 &hellip; <a href=\"https:\/\/www.ar-cad.com\/smallguru\/2008\/12\/opensource-c-graph-plot-library-zedgraph\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":63,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","footnotes":""},"categories":[5,7,8],"tags":[35,37,29],"class_list":["post-33","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-inventor-customization","category-tutorials","category-visual-c","tag-inventor-customization","tag-visual-c","tag-visual-studio"],"_links":{"self":[{"href":"https:\/\/www.ar-cad.com\/smallguru\/wp-json\/wp\/v2\/posts\/33","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ar-cad.com\/smallguru\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ar-cad.com\/smallguru\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ar-cad.com\/smallguru\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ar-cad.com\/smallguru\/wp-json\/wp\/v2\/comments?post=33"}],"version-history":[{"count":0,"href":"https:\/\/www.ar-cad.com\/smallguru\/wp-json\/wp\/v2\/posts\/33\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.ar-cad.com\/smallguru\/wp-json\/wp\/v2\/media?parent=33"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ar-cad.com\/smallguru\/wp-json\/wp\/v2\/categories?post=33"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ar-cad.com\/smallguru\/wp-json\/wp\/v2\/tags?post=33"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}