Click here to Skip to main content
15,885,546 members
Articles / Programming Languages / C#
Tip/Trick

QuickPlot Utility

Rate me:
Please Sign up or sign in to vote.
4.92/5 (5 votes)
9 Apr 2018CPOL3 min read 12K   295   12   2
Easy to Use Plotting Utility

Quick Plot Screen Shot

Introduction

This is a simple program I developed recently as I was looking for a way to quickly plot some data points by just piping the data from a CSV file into a plotting utility using the DOS command line and type command:

C:\MyData>type SampleData.csv | QuickPlot.exe

With bash, you could use the cat command:

$ cat SampleData.csv | QuickPlot.exe

For those who are not familiar with the pipe character ('|') in shell command lines, it is used to send the standard output from the left hand command directly to the standard input of the command on the right hand side of the pipe. Thus, the output of the type (or cat) command, that is, the contents of the data file, goes directly into the standard input of the QuickPlot program.

(In both cases, we are assuming that the SampleData.csv file is in the same directory as the executable. Otherwise, you must specify the paths explicitly.)

There is also the usual File->Open command on the menu to read and plot a data file. The file SampleData.csv shows the data format. Essentially, you can have one or more named series of data that are plotted as X-Y pairs. For example, here is a series named "Airfoil 1", and the X-Y data pairs follow, separated by commas:

Series,Name:Airfoil 1,ChartType:Spline
-5.0,0.0
+0.0,0.52
+5.0,1.05
+10.0,1.45
+15.0,1.70

ChartType can be "Spline" or "Point" to draw a line, or just the data points, respectively. The file SampleData.csv contains three such series.

The labels for the X and Y axes, title of the plot, and title font can be specified as in the following example:

C#
Chart,AxisX:Angle of Attack (°),AxisY:Lift Coefficient,
Title:Airfoil Wind Tunnel Study,FontFamily:Helvetica,FontEmSize:16.0

Using the Code

Download and open the QuickPlot project with Visual Studio. Build it by pressing F6. The code to parse the CSV file is encapsulated in a class called ParseCSVFile. The idea here is that if you have a data file with a different format, this should be the only class that needs to be modified.

When using the pipe operator as described above, that is, when no file name is specified, the data stream constructor to read from standard input is:

C#
streamReader = new StreamReader(Console.OpenStandardInput(), encoding);

Otherwise, if a file is specified via the File->Open command on the menu, it is supplied to the StreamReader constructor using the full path to the file as specified in the fullPath variable:

C#
streamReader = new StreamReader(fullPath, encoding);

This project uses the powerful System.Windows.Forms.DataVisualization.Charting.Chart namespace. The field chart1 is the actual chart in the QuickPlotForm and performs all of the "heavy lifting" of plotting the data. You can set the axis titles, the chart title, the data series, and so on, directly via the chart1 field. For example, to set the title of the chart, you can simply set chart1.Titles["Title1"].Text = "My Title"

I added a System.Windows.Forms.DataGridView in order to display the data in tabular form. This is the field dataGridView1 in the QuickPlotForm. To specify the data source, you can use the ComboBox labelled "Series" to set the dataGridView1.DataSource to the desired table created by the GridDataTable.GetTables() method. Each table corresponds to a series in the input file. You can use the File->Show Grid to display the data on the right-hand side of the form; File->Hide Grid will hide the grid.

Image 2

I used Jeff Atwood and Scott Ferguson's Generic About Box dialog under Help->About.

History

  • April 04, 2018: Version 1.0

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United States United States
Chuck Peasley is a developer in Orange County, CA

Comments and Discussions

 
QuestionDifference between this and gnuplot? Pin
Member 133016799-Apr-18 23:26
Member 133016799-Apr-18 23:26 
QuestionLooks cool! Pin
LightTempler9-Apr-18 10:30
LightTempler9-Apr-18 10:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.