Skip to content

Instantly share code, notes, and snippets.

@cofearabi
Last active June 15, 2016 15:40
Show Gist options
  • Save cofearabi/4443524 to your computer and use it in GitHub Desktop.
Save cofearabi/4443524 to your computer and use it in GitHub Desktop.
(C#) diaplay a chart from csv data
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
using System.Data.OleDb;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// Full path to the data source file
string file = "6954.csv";
string path = "\\mdb";
// Create a connection string.
string ConStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+
path+ ";Extended Properties=\"Text;HDR=No;FMT=Delimited\"";
OleDbConnection myConnection = new OleDbConnection(ConStr);
// Create a database command on the connection using query
string mySelectQuery = "Select * from "+ file;
OleDbCommand myCommand = new OleDbCommand(mySelectQuery, myConnection);
// Open the connection and create the reader
myCommand.Connection.Open();
OleDbDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
// Column 1 is a time value, column 2 is a double
// databind the reader to the chart using the DataBindXY method
chart1.Series[0].Points.DataBindXY(myReader, "0", myReader, "2");
chart1.Series[0].ChartType = SeriesChartType.Line;
//chart1.Series[0].ChartType = SeriesChartType.Stock;
// Close connection and data reader
myReader.Close();
myConnection.Close();
}
}
}
@dimipeti
Copy link

Hi ,
Could i ask what "\mdb" should be?
Thanks in advance

@NewMihai
Copy link

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment