hey people,
i still have a problem about how to moove from a DataTable full with csv Value to a multi-line chart.
The fact is,in my DataTable,i have many value of censor(in °C,KWh,Mwh..)and i want to represent for each censor value a multi-line chart,with Date and time in X Axis,and with two Y axis the Legend and value of censor.
i joined a sample of csv to fell my DataTable
that is the part of my code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using Microsoft.VisualBasic;
using System.Globalization;
using System.Drawing.Drawing2D;
using ZedGraph;
using System.Linq;
using System.Windows.Forms.Integration;
public DataTable BuildDataTable(string fileFullPath, char seperator)
{
const int EOF = -1;
DataTable myTable = new DataTable("MyTable");
DataRow myRow;
StreamReader myReader = new StreamReader(fileFullPath);
string Set_Data = myReader.ReadLine();
int Set_len = Set_Data.Length;
try
{
myReader = new StreamReader(fileFullPath);
}
catch (Exception ex)
{
MessageBox.Show("Fout bij openen bestand: " + ex.Message);
return new DataTable("Empty");
}
try
// Open file and read first line to determine how many fields there are.
{
string[] fieldValues = new string[Set_len];//myReader.ReadLine().Split(new Char[] { seperator, '\t' });
//skip title
// Title = fieldValues[2];
//string [] Get_val = myReader.ReadLine().Split(new Char[] { seperator, '\t' });
//fieldValues = myReader.ReadLine().Split(new Char[] { seperator, '\t' });
fieldValues = myReader.ReadLine().Split(new Char[] { seperator, '\t', });
// Adding the first line of data to data table (columnnames)
// Create data columns accordingly
for (int i = 0; i < fieldValues.Length; i++)
{
//if (i==0) myTable.Columns.Add(new DataColumn("Code"));
//if (i==1) myTable.Columns.Add(new DataColumn("Datum"));
myTable.Columns.Add(new DataColumn(fieldValues[i].ToString().Trim()));
}
//Now reading the rest of the data to data table
while (myReader.Peek() != EOF)
{
fieldValues = myReader.ReadLine().Split(new Char[] { seperator, '\t' });
myRow = myTable.NewRow();
for (int i = 0; i < fieldValues.Length; i++)
{
myRow[i] = fieldValues[i].ToString().Trim();
}
myTable.Rows.Add(myRow);
}
}
catch (Exception ex)
{
MessageBox.Show("Error building datatable: " + ex.Message);
return new DataTable("Empty");
}
finally
{
if (myReader != null)
{
myReader.Close();
}
}
myTable.AcceptChanges();
if (myReader != null)
{
myReader.Close();
}
dataGridView1.DataSource = myTable;
return myTable;
}
public void Proces_File()
{
char[] Separator = { ';', ':' };
String Choose_File;
DataTable DT;
OpenFD.InitialDirectory = "Y:\\";
OpenFD.Filter = "txt files(*.txt)|*.txt|All Files(*.*)|*.*";
OpenFD.FilterIndex = 2;
OpenFD.RestoreDirectory = true;
if (OpenFD.ShowDialog() != DialogResult.Cancel)
{
Choose_File = OpenFD.FileName;
richTextBox1.LoadFile(Choose_File, RichTextBoxStreamType.PlainText);
DT = BuildDataTable(OpenFD.FileName, ';');
this.dataGridView1.DataSource = DT;
}
private void button3_Click(object sender, EventArgs e)
{
Proces_File();
}
thx in advance