直列つなぎ。 -とある発達障害者の記録

知識と知識を繋ぐためのblog。 広汎性発達と診断されました。ぜんぜん役に立ってないけど。月収13万円、家賃4万円で生活するひつじ人間。

グラフでCSVを読み取るC#code




https://gist.github.com/cofearabi/4443524
より

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();

}

}
}
関連記事
スポンサーサイト

 Archives

0 Comments

Leave a comment