Assuming that:
richTextBox
is an instance of theSystem.Windows.Forms.RichTextBox
class;chart
is an instance of theSystem.Windows.Forms.DataVisualization.Charting.Chart
class.
The following method is intended for parsing an array of string
s:
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));
});
}
Usage:
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);