private void upDateOneChartStaticSimulate(Chart chartHistory, HistoryDataReader dataReader) { //calculate the range od the array. double low_index = (dataReader.PageIndex > 0) ? dataReader.PageIndex - 0.5 : 0; int low = 0; int high = 0; low = (int)(low_index * dataReader.interval); high = low + dataReader.interval; if (high > dataReader.length) { high = dataReader.length; } //set the range of the chart for the real time style. chartHistory.ChartAreas["ChartAreaRealData"].AxisX.Maximum = (high - low); chartHistory.ChartAreas["ChartAreaRealData"].AxisX.Minimum = 0; //customized the label of x axis CustomLabel label1 = new CustomLabel(); label1.FromPosition = (high - low) - (high - low) / 15; label1.ToPosition = (high - low) + (high - low) / 15; label1.Text = high.ToString(); label1.RowIndex = 0; CustomLabel label2 = new CustomLabel(); label2.FromPosition = (high - low) / 2 - (high - low) / 15; label2.ToPosition = (high - low) / 2 + (high - low) / 15; label2.Text = "Middle"; label2.RowIndex = 0; CustomLabel label3 = new CustomLabel(); label3.FromPosition = -(high - low) / 15; label3.ToPosition = (high - low) / 15; label3.Text = low.ToString(); label3.RowIndex = 0; chartHistory.ChartAreas["ChartAreaRealData"].AxisX.CustomLabels.Clear(); chartHistory.ChartAreas["ChartAreaRealData"].AxisX.CustomLabels.Add(label1); chartHistory.ChartAreas["ChartAreaRealData"].AxisX.CustomLabels.Add(label2); chartHistory.ChartAreas["ChartAreaRealData"].AxisX.CustomLabels.Add(label3); //add the 0 data for (int i = low; i < high; i++) { if (chartHistory.Series["Attention"].Points.Count > chartHistory.ChartAreas["ChartAreaRealData"].AxisX.Maximum) { chartHistory.Series["Attention"].Points.RemoveAt(0); } chartHistory.Series["Attention"].Points.Add(dataReader.intention[i]); if (chartHistory.Series["Meditation"].Points.Count > chartHistory.ChartAreas["ChartAreaRealData"].AxisX.Maximum) { chartHistory.Series["Meditation"].Points.RemoveAt(0); } chartHistory.Series["Meditation"].Points.Add(dataReader.meditation[i]); } }
private void timer1_Tick_OneChart(Chart chartHistory, HistoryDataReader dataReader, Label label, int ButtonIndex) { string line; if ((line = dataReader.sReader.ReadLine()) != null) { //using label to show the orginal data label.Text = line; string[] words = line.Split(' '); // System.Console.WriteLine("1"); if (chartHistory.Series["Attention"].Points.Count > chartHistory.ChartAreas["ChartAreaRealData"].AxisX.Maximum) { chartHistory.Series["Attention"].Points.RemoveAt(0); } chartHistory.Series["Attention"].Points.Add(Convert.ToInt32(words[6])); //System.Console.WriteLine(e.ThinkGearState.Attention); if (chartHistory.Series["Meditation"].Points.Count > chartHistory.ChartAreas["ChartAreaRealData"].AxisX.Maximum) { chartHistory.Series["Meditation"].Points.RemoveAt(0); } chartHistory.Series["Meditation"].Points.Add(Convert.ToInt32(words[7])); //System.Console.WriteLine(e.ThinkGearState.Meditation); switch (ButtonIndex) { case 1: CalculateUserState(chartHistory.Series["Attention"].Points, chartHistory.Series["Meditation"].Points, chartHistory, btnRelax1, btnEngagement1, btnProductivity1); break; case 2: CalculateUserState(chartHistory.Series["Attention"].Points, chartHistory.Series["Meditation"].Points, chartHistory, btnRelax2, btnEngagement2, btnProductivity2); break; case 3: CalculateUserState(chartHistory.Series["Attention"].Points, chartHistory.Series["Meditation"].Points, chartHistory, btnRelax3, btnEngagement3, btnProductivity3); break; default: break; } } else { label.Text = "Unchanged"; timer1.Enabled = false; } }