Plot chart using values from richTextBox C#


is it possible to plot graphs of data that are collected from a richTextBox? For example I have following text in richTextBox:

$GPRMC,152908.00,A,5307.0794359,N,02308.8918827,E,0.049,188.6,280612,0.0,E,D*3A $GPRMC,152909.00,A,5307.0794307,N,02308.8918792,E,0.081,193.3,280612,0.0,E,D*3A $GPRMC,152910.00,A,5307.0794343,N,02308.8918811,E,0.034,42.9,280612,0.0,E,D*0F $GPRMC,152911.00,A,5307.0794410,N,02308.8918827,E,0.099,1.3,280612,0.0,E,D*30 $GPRMC,152912.00,A,5307.0794461,N,02308.8918808,E,0.055,331.9,280612,0.0,E,D*32

And I want plot chart for example Latitude(time):

5307.0794359 -> 152908.00 5307.0794307 -> 152909.00 5307.0794343 -> 152910.00 5307.0794410 -> 152911.00 5307.0794461 -> 152912.00

I dont how to write a function, that will retrieve Latitude from lines[1,2,3,4,5] and time from lines [1,2,3,4,5]. And then plot a chart.

I need a universal function, because I can have data which 100 lines or 400 lines etc.

Can anyone help me? Counts for me any help (code, example, tips or links).


Assuming that:

<ul><li>richTextBox is an instance of the System.Windows.Forms.RichTextBox class;</li> <li>chart is an instance of the System.Windows.Forms.DataVisualization.Charting.Chart class.</li> </ul>

The following method is intended for parsing an array of strings:

private static readonly CultureInfo EnglishCulture = CultureInfo.GetCultureInfo("en-US"); private static Tuple<double, double>[] GetData(string[] lines) { return Array.ConvertAll(lines, line => { string[] elems = line.Split(','); return new Tuple<double, double>(double.Parse(elems[3], EnglishCulture), double.Parse(elems[1], EnglishCulture)); }); }


var data = GetData(richTextBox.Lines);

Now you only need to bind this data array as a chart's DataSource or manually add them to the series as shown below:

chart.Series.Clear(); Series series = new Series("sample") { ChartType = SeriesChartType.Line, BorderWidth = 2, MarkerSize = 5, MarkerStyle = MarkerStyle.Square }; foreach (var p in data) series.Points.Add(p.Item1, p.Item2); chart.Series.Add(series);


I find answer for my question. I change "a litle" one line in code created by Dmitry. Here it is:

Previously code:

private static readonly CultureInfo EnglishCulture = CultureInfo.GetCultureInfo("en-US");

New code (just added <strong>System.Globalization.</strong> before CultureInfo) and it works on Visual Studio 2012 Ultimate), before change I have error "CultureInfo not found":

private static readonly System.Globalization.CultureInfo EnglishCulture = CultureInfo.GetCultureInfo("en-US");

I dont know why previously code dont work at me .. Maybe its by Visual System version. However all works now fine, and it's funny because now it works on previously code too, and the same with new change. I dont know whats going on, but all is fine.

Thanks Dmitry, for Your help.

PS. VERRY IMPORTANT (at the beginning we must declare this):

using System.Globalization;


  • How do I convert a ResultSet in a List of Hashtable?
  • Excluding multiple values from the array
  • Get highest value from a file using mSL and mIRC
  • How to override JAXB @XMLAccessorType(XMLAccessType.FIELD) specified at a Class level with @XMLEleme
  • Programmatically set PIN/Password used to unlock device
  • Facebook Open Graph Story Custom Actions Keep Getting Rejected - Advice Please?
  • finding symmetric difference/unique elements in multiple arrays in javascript
  • byebug, next into application code only
  • What are zone turns?
  • Microsoft Chart Controls for Microsoft .NET Framework 4.0
  • Rails 3.2 from SQLite locally to Postgres on Heroku
  • Is mp4 stream able with ffserver?
  • Python/Javascript: WYSIWYG html editor - Handle large documents fast and/or design theory
  • IE10 strips out hashtag from the URL
  • XSLT foreach repeating nodes to flat
  • How to use Windows Media Foundation with UWP without a topology
  • Unable to get column index with table.getColumn method using custom table Model
  • R - Combining Columns to String Based on Logical Match
  • Can I display google adwords (AdView) in javafx on android
  • Read text file and split every line in MSBuild
  • Can I make an Android app that runs a web view in Chrome 39?
  • Matplotlib draw Spline from multiple points
  • Return words with double consecutive letters
  • XCode can't find symbols for a specific iOS library/framework project
  • Calling of Constructors in a Java
  • How do I rollback to a specific git commit
  • how to add data labels for bar graph in matlab
  • Compare two NSDates in iPhone
  • Transpose CSV data with awk (pivot transformation)
  • Use group_by to filter specific cases while keeping NAs
  • log4net write single file for each call to log.info
  • Benchmarking RAM performance - UWP and C#
  • Acquiring multiple attributes from .xml file in c#
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • How can I remove ASP.NET Designer.cs files?
  • Binding checkboxes to object values in AngularJs
  • java string with new operator and a literal
  • Net Present Value in Excel for Grouped Recurring CF
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize
  • How to load view controller without button in storyboard?