I have need to create an oscilloscope simulator using the ms-chart control. I store my data in an array. But I don't know how to create the "moving effect" - continuous update of the control. (adding / removing points from the chart control) and having a vertical line drawn every second on the control.
My code is:
private void Form1_Load(object sender, EventArgs e)
{
chart1.Series["Series1"].ChartType = SeriesChartType.Line;
chart1.Series["Series1"].BorderWidth = 3;
// NO grids
chart1.ChartAreas[0].AxisX.MajorGrid.LineWidth = 0;
chart1.ChartAreas[0].AxisY.MajorGrid.LineWidth = 0;
chart1.PostPaint += new EventHandler<ChartPaintEventArgs>(chart1_PostPaint);
}
void chart1_PostPaint(object sender, ChartPaintEventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
string fileContent = File.ReadAllText("e:\\in.txt");
string[] integerStrings = fileContent.Split(new char[] { ' ', '\t', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
int[] integers = new int[integerStrings.Length];
for (int n = 0; n < integerStrings.Length; n++)
{
integers[n] = int.Parse(integerStrings[n]);
chart1.Series["Series1"].Points.Add(integers[n]);
}
}
Try this: