minValue
= DateTime
.Now;
maxValue
= minValue.AddSeconds(30);
chart1.ChartAreas[0].AxisX.Minimum =
minValue.ToOADate();
chart1.ChartAreas[0].AxisX.Maximum =
maxValue.ToOADate(); //设置X轴为时间的范围
public void AddNewPoint( DateTime timeStamp,
System.Windows.Forms.DataVisualization.Charting. Series ptSeries
)
{
// Add new data point to its
series.
ptSeries.Points.AddXY(
timeStamp.ToOADate(), rand.Next(10, 20));
// remove all points from the source series older than 20
seconds.
double removeBefore = timeStamp.AddSeconds( ( double )(20) * ( -1
)).ToOADate();
//remove oldest values to maintain a constant number of data
points
while ( ptSeries.Points[0].XValue < removeBefore
)
{
ptSeries.Points.RemoveAt(0);
}
chart1.ChartAreas[0].AxisX.Minimum =
ptSeries.Points[0].XValue;
chart1.ChartAreas[0].AxisX.Maximum = DateTime .FromOADate(ptSeries.Points[0].XValue).AddSeconds(30).ToOADate();
chart1.Invalidate();
}