How to use it.
1. Create one or more StripChart.Line objects. The last parameter is actually a function that the StripChart control will call every StripChart.UpdateInterval milliseconds.
C#
- Code: Select all
_sine = new StripChart.Line(Color.FromArgb(0xFF, 0x00, 0x00), ComputeSine);
_cosine = new StripChart.Line(Color.FromArgb(0x00, 0x00, 0xFF), ComputeCosine);
private StripChart.Line.DataPoint ComputeSine()
{
double t = (double)GetTickCount() / 1000.0d - _t0;
double amplitude = (_stripChart.YMaximum - _stripChart.YMinimum) / 2.0d;
return new StripChart.Line.DataPoint(t, amplitude * Math.Sin(Frequency * t));
}
private StripChart.Line.DataPoint ComputeCosine()
{
double t = (double)GetTickCount() / 1000.0d - _t0;
double amplitude = (_stripChart.YMaximum - _stripChart.YMinimum) / 2.0d;
return new StripChart.Line.DataPoint(t, amplitude * Math.Cos(Frequency * t));
}
VB
- Code: Select all
_sine = New StripChart.Line(Color.FromArgb(&HFF, &H0, &H0), AddressOf ComputeSine)
_cosine = New StripChart.Line(Color.FromArgb(&H0, &H0, &HFF), AddressOf ComputeCosine)
Private Function ComputeSine() As StripChart.Line.DataPoint
Dim t As Double = CDbl(GetTickCount()) / 1000.0 - _t0
Dim amplitude As Double = (_stripChart.YMaximum - _stripChart.YMinimum) / 2.0
Return New StripChart.Line.DataPoint(t, amplitude * Math.Sin(Frequency * t))
End Function
Private Function ComputeCosine() As StripChart.Line.DataPoint
Dim t As Double = CDbl(GetTickCount()) / 1000.0 - _t0
Dim amplitude As Double = (_stripChart.YMaximum - _stripChart.YMinimum) / 2.0
Return New StripChart.Line.DataPoint(t, amplitude * Math.Cos(Frequency * t))
End Function
2. Add the Lines to the StripChart control.
C#
- Code: Select all
_stripChart.AddLine(_sine);
_stripChart.AddLine(_cosine);
VB
- Code: Select all
_stripChart.AddLine(_sine)
_stripChart.AddLine(_cosine)
3. Specify how often the StripChart control should update.
C#
- Code: Select all
_stripChart.UpdateInterval = 100;
VB
- Code: Select all
_stripChart.UpdateInterval = 100
4. Specify the minimum and maximum values for the Y Axis using StripChart.YMinimum and StripChart.YMaximum.
5. Specify the amount of time one full screen should be with StripChart.Range. Be sure StripChart.Range, StripChart.XAxisGridLines.OnEvery, and DataPoint.X all use the same units (i.e. minutes, seconds, milliseconds, etc...)
6. (Optional) Add grid lines. Example: If StripChart.YMinimum is -100.0 and StripChart.YMaximum is +100.0 and YAxisGridLines.OnEvery = 20.0, then there will be one grid line for every 20.0 units between -100 and 100, for a total of 10 divisions.
C#
- Code: Select all
_xAxisGridLines = new StripChart.GridLines(Color.FromArgb(0x99, 0x99, 0x99), 1.0d);
_yAxisGridLines = new StripChart.GridLines(Color.FromArgb(0x99, 0x99, 0x99), 20.0d);
_stripChart.XAxisGridLines = _xAxisGridLines;
_stripChart.YAxisGridLines = _yAxisGridLines;
VB
- Code: Select all
_xAxisGridLines = New StripChart.GridLines(Color.FromArgb(&H99, &H99, &H99), 1.0)
_yAxisGridLines = New StripChart.GridLines(Color.FromArgb(&H99, &H99, &H99), 20.0)
_stripChart.XAxisGridLines = _xAxisGridLines
_stripChart.YAxisGridLines = _yAxisGridLines
This code can be optimized to provide better performance, but it will make it quite a bit more complicated. I hope, at least, this can serve as a model from which you can make your own implementation.