Zedgraph C# Graph Plot Example Application

Update : 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 is a very good opensource C# graph plotting library. Check out more details at my earlier post on Zedgraph. I have gone a step forward and made availabe source code and exe of a sample Zedgraph application which lets you have Line Plot, Bar Graph and Pie Chart.

Download Source Code (Visual Studio 2005 project in C#)

Download EXE

Below are the Screenshots of the Window Application. Copy and paste 2 columns of data from your favorite spreadsheet(eg MS Excel, Open Office Calc etc). NewLine and Tab delimiters are identified and the data is sorted accordingly, and added to graph plots. The Zedgraph plot library is so easy to use, implement and extend that it just took an afternoon to come up with this Windows application, when I was trying to convince my cousin to use ZedGraph in his college project.

ZedGraph is also being used to plot graphs in IN-Motion, a Motion Simulation Addin for Autodesk Inventor which I am co-developing along with my mentor. We are using ZedGraph to plot Postition-Velocity-Acceleration data, and intend to use it further more in Force-Torque graphs etc. Thanks to ZedGraph team for such a wonderful effort 🙂

Figure 1: ZedGraph Sample Window Application

Figure 2: The plot data for Line Plot and BarGraph are copied from a spreadsheat (eg MS Excel) and pasted in the text area. The code then uses tab and newLine delimiters to arrange data for plotting.

Figure 3: Line Plot for the above data. Notice the Titles of the X and Y axes.

Figure 4: Bargraph for the above data.

Figure 5: Data for Pie Chart. Paste 2 columns from spreadsheet. You may also use normal textbox to get the data from the user.

Figure 6: Pie Chart for the above data.

Download Source Code (Visual Studio 2005 project in C#)

Download EXE

24 thoughts on “Zedgraph C# Graph Plot Example Application

  1. Pingback: Opensource C# Graph Plotting library- ZedGraph v/s NPlot | SmallGuru

  2. Hello,
    Thanks for the information.
    Actually I’m new to Visual studio 2005. I was in search for some plotting utility. I am writing my code in C++.
    I have seen zedgraph’s website, but I do not understand creating ‘user control’.
    I have downloaded their dll file and source file from the website.
    Could you please tell me step by step procedure to follow to

    >install the library [when I try to ‘add reference’ to my win32 console application it shows only one tab, and not the .NET,COM and other tabs]

    >Write a simple program to plot some data

    >Also how does this library work? do i have to add some header file for it to work in my program?

    Thanks very much.

  3. Hi
    How would I do to rewrite/change the graph when the data in the textbox is changed? Now only one chart can be written, then the form must be closed.

  4. hi to all,
    I want to draw line from Both X and Y axis for Particular point after plotting. please suggest me

    Thnks in advnce,
    Gopal

  5. @Lesse,
    When the data in the Textbox is changed, you just need to click on the buttons “Line Plot”, “Bar Graph” or “Pie Chart”. New data is read and plotted accordingly.

  6. hello Rajeev,
    I want to draw a lines from both X and Y to particular point where in clicked on pane

    Thnks in advnce
    Gopal

  7. @Gopal,
    I am not very sure on drawing lines from X and Y axes to a particular clicked point.

    What I can think of is as follows:
    a) Have a Transparent control on the Zedgraph plot and try to capture OnClick event. From that, you could get the (x,y) of the clicked point.
    b) Try to plot lines from X and Y axes to that point.
    c) Each line will be a PointPairList, which will just have 2 set of data.
    d) Draw that 2 lines as you would draw a graph.

    I hope it is clear., let me know if you still have any doubts.

    Regards,
    Rajeev

  8. Friends,

    Can any one please help me with the code to plot a single graph with a single X-Axis and two Y-axis, one as Primary Y-Axis and another as Secondary Y-Axis.(i.e. one Y-Axis is in the extreme left of the X-Axis and another one in extreme right of the X-Axis.

    Thanks and Regards,
    Tiju.

  9. Hello! I need some help regarding loading an image with zedgraph…
    I don’t know if there is any possibility to load an image in the zedgraphcontrol, but I find a property “BackgroundImage”….I’ve tried to load an image by setting the property above, but no image is loading on background…If anyone has any idea or some functional code example(s) I’ll be very grateful!
    Thanks! (please it’s urgent)

    PS: I need to load image with zedgraph because It’s a control with axes, and I need to represent on the axes some values (the image is a spectrogram an I need to represent on the axes frequencies and positions).

  10. Hi
    I am new to graph control, I saw this zedgraph control, It s look like very good. I want to include that graph, but i want it should be generated automatically based on database record . can any one help me. my email id is aravindcgovindaraj@gmail.com

    Thanks and Regards
    Aravind G

  11. hi,
    i need to write text on Yaxis, and to draw the bar height according to the text, and not double, like all the examples here..

    can you help me?

  12. X Y
    25 100
    21 99
    17 97
    13 98
    9 97.5
    5 95
    1 95.3

    As you can see the X axis has a decending number sequence. However zedgraph does not reflect this. Is their anyway I can specify the start of the X axis as 25 and decrement in units of 4 to reflect the data.

    Any help would be much appreciated.

  13. @ Ohad,

    The default X axis value starts from zero. The order in which you have the values, are added to a pointList (m_pointsList in our case). It is then passed on to m_graphPane.AddCurve(txtPlotTitle.Text, m_pointsList, Color.Blue, SymbolType.Star);

    I think Zedgraph draws the data points and connects them. The X axis always goes from 0 to max number.

    If you are keen, you may give values of X in negative (to see your trend)
    -25 2
    -21 5
    -17 4
    -13 7
    -9 2
    -5 9
    -1 4

    Let me know if its OK. Otherwise, you may have to check into ZedGraph API on how to change the axis.

    Rajeev

  14. sir
    i am creating a Question bank project for storing Subject wise question but i want to create some figers and diagram and those are store in database so how can i do
    pls help me

  15. Hello Rajeev!

    I have a project with 6 particle counters.Each particle counter has 6 channels being:First is product ID = 01, 02, 03, 04, 05, 06.Second is 2mm.Third is 7mm.Room is 10mm.The other two are for error messages and will not use in the charts.It is possible we use ZedGraph and create a dynamic chart, ie in real time?

    Regards,
    ocaccy

  16. Hi Rajeev,

    Can ZedGraph plot serial input data as it receives from serial port? If Yes, Will it work realtime? I Mean as it receives data will it plot it on zedgraph?
    I tried doing it,but did not succeed.

Leave a Reply

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