Skip to content

Instantly share code, notes, and snippets.



Last active Jun 15, 2016
What would you like to do?
(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()
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
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

This comment has been minimized.

Copy link

@dimipeti dimipeti commented Jan 17, 2015

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


This comment has been minimized.

Copy link

@NewMihai NewMihai commented Jun 15, 2016


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.