CWD Posted March 22, 2011 Posted March 22, 2011 (edited) I have a log file that is saves data every day, each day new data is append to a new line of this log file. I will show you what this log file kind of looks like. Each log file line has 4 parts of data separated by commas. 03-01-2011,4.05,87,141 03-02-2011,4.10,88,138 03-03-2011,4.17,90,135 03-04-2011,4.20,86,115 03-05-2011,4.25,84,126 03-06-2011,4.31,81,132 03-07-2011,4.35,82,109 03-08-2011,4.42,78,136 03-09-2011,4.47,86,110 03-10-2011,4.53,83,108 I just need my chart to load this log file and loop through it and populate my line chart. I am able to make a line chart and populate it from a text file but only in a long way. I first load all the data to 10 text boxes, then I split all the data into 40 other text boxes then I use that to populate the chart, There has to be a easier way of doing this. With my current way I can only load up 10 days of data. I would like to be able to load up 30 days of data or even a years worth (365 entry's) I am using visual basic 2008 with .NET Framework 4 Chart Controls. Thanks for reading this. Some of my code: Chart1.Series.Clear() Chart1.Titles.Add("Progress Chart") 'Create a new series and add data points to it. Dim s As New Series Dim t As New Series Dim u As New Series s.Name = "Weight" t.Name = "Oxygen" u.Name = "Heartrate" 'Change to a line graph. s.ChartType = SeriesChartType.Spline t.ChartType = SeriesChartType.Spline u.ChartType = SeriesChartType.Spline s.Points.AddXY(TextBox1.Text, TextBox11.Text) s.Points.AddXY(TextBox2.Text, TextBox12.Text) s.Points.AddXY(TextBox3.Text, TextBox13.Text) s.Points.AddXY(TextBox4.Text, TextBox14.Text) s.Points.AddXY(TextBox5.Text, TextBox15.Text) s.Points.AddXY(TextBox6.Text, TextBox16.Text) s.Points.AddXY(TextBox7.Text, TextBox17.Text) s.Points.AddXY(TextBox8.Text, TextBox18.Text) s.Points.AddXY(TextBox9.Text, TextBox19.Text) s.Points.AddXY(TextBox10.Text, TextBox20.Text) t.Points.AddXY(TextBox1.Text, TextBox21.Text) t.Points.AddXY(TextBox2.Text, TextBox22.Text) t.Points.AddXY(TextBox3.Text, TextBox23.Text) t.Points.AddXY(TextBox4.Text, TextBox24.Text) t.Points.AddXY(TextBox5.Text, TextBox25.Text) t.Points.AddXY(TextBox6.Text, TextBox26.Text) t.Points.AddXY(TextBox7.Text, TextBox27.Text) t.Points.AddXY(TextBox8.Text, TextBox28.Text) t.Points.AddXY(TextBox9.Text, TextBox29.Text) t.Points.AddXY(TextBox10.Text, TextBox30.Text) u.Points.AddXY(TextBox1.Text, TextBox31.Text) u.Points.AddXY(TextBox2.Text, TextBox32.Text) u.Points.AddXY(TextBox3.Text, TextBox33.Text) u.Points.AddXY(TextBox4.Text, TextBox34.Text) u.Points.AddXY(TextBox5.Text, TextBox35.Text) u.Points.AddXY(TextBox6.Text, TextBox36.Text) u.Points.AddXY(TextBox7.Text, TextBox37.Text) u.Points.AddXY(TextBox8.Text, TextBox38.Text) u.Points.AddXY(TextBox9.Text, TextBox39.Text) u.Points.AddXY(TextBox10.Text, TextBox40.Text) 'Add the series to the Chart1 control. Chart1.Series.Add(s) Chart1.Series.Add(t) Chart1.Series.Add(u) The Date has to be at the bottom of this chart (going left to right) and the numbers on the left side. Edited March 22, 2011 by CWD Quote
Administrators PlausiblyDamp Posted March 23, 2011 Administrators Posted March 23, 2011 Out of interest why are you loading these values into textboxes anyway? Could you not just read a line from the file, split it into it's 4 parts and then add the point to the chart and then read the next line etc? I am assuming you already have the code to read the lines and the code to split a line so I am unsure why there is the extra steps involving populating textbox controls. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
CWD Posted March 23, 2011 Author Posted March 23, 2011 Its because I am not an advanced coder and am really new to chart controls. I found an example how to make a chart using text boxes so thats where I started, lol I did get this problem sorted out today, here is the finished code: Dim ReadChart As String ReadChart = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\Charts\chart.txt" Dim ChartValues As StreamReader = New StreamReader(ReadChart) Chart1.Series.Clear() Chart1.Titles.Add("Progress Chart") 'Create a new series and add data points to it. Dim s As New Series Dim t As New Series Dim u As New Series ' Name of the series s.Name = "Weight" t.Name = "Oxygen" u.Name = "Heartrate" 'Change to a line graph. s.ChartType = SeriesChartType.Spline t.ChartType = SeriesChartType.Spline u.ChartType = SeriesChartType.Spline While ChartValues.Peek <> -1 Dim values() As String = ChartValues.ReadLine.Split(","c) s.Points.AddXY(values(0), values(1)) t.Points.AddXY(values(0), values(2)) u.Points.AddXY(values(0), values(3)) End While 'Add the series to the Chart1 control. Chart1.Series.Add(u) Chart1.Series.Add(t) Chart1.Series.Add(s) Thanks for trying to help me out guys. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.