1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| public partial class Form1 : Form
{
public Form1( )
{
StreamReader sr = new StreamReader(@"C:\time.txt");
string line = sr.ReadLine();
//string s = sr.ReadLine();
InitializeComponent();
while (!sr.EndOfStream)
{
line = sr.ReadLine();
Regex maRegex = new Regex(@"Time:(?<heure>(\d{2}/){2}\d{4} (\d{2}:){2}\d{2}) \r\nData:(?<donnee>\d+) ");//Regex qui reprend le format des 2 lignes de données et donne un mon aux parties de texte qui nous importent
MatchCollection matches = maRegex.Matches(line);
Points = new List<Coordonnees>();
for (int i = 0; i < matches.Count; i++)//la requete Linq ne marche pas avec matchcollection, donc je fais un for
Points.Add(new Coordonnees
{
Data = int.Parse(matches[i].Groups["donnee"].Value),
Heure = DateTime.Parse(matches[i].Groups["heure"].Value)
});
chart1.Series[chart1.Series.Count - 1].Points.AddXY(double.Parse(line.Split(';')[0]), double.Parse(line.Split(';')[1])); // le problème
}
chart1.Series[chart1.Series.Count - 1].ChartType = SeriesChartType.FastLine;
chart1.Series[chart1.Series.Count - 1].Color = Color.Red;
sr.Close();
}
public List<Coordonnees> Points { get; set; }
private void Form1_Load(object sender, EventArgs e)
{
}
}
public class Coordonnees
{
public int Data { get; set; }
public DateTime Heure { get; set; }
public override string ToString()
{
return string.Format("{0}: {1}", Heure.ToShortTimeString(), Data);
}
} |