この例は、microsfot Web サイトのサンプルから取得しました。例は、C# のリアルタイムの Date&Time です。この例は、短距離を使用して基本的にそのまま実行すると完全に機能しますが、グラフを少なくとも 45 分 - 1 時間監視できるようにする必要があり、その後で値が低下し始める必要があります。私がやりたいのは、約 5 分間の視聴時間と、プロットされたグラフの残りの部分をスクロールバックできるようにすることです。ということで、以下が問題のエリアです。スクロールする前にグラフに表示できる量を設定するためにスケール ビューを追加する必要があります (これも機能しません)。ただし、スケール ビューを 1 より上にすると、X 軸の値ラベルは挿入されません。もしそうなら、そのうちの1つだけで、それ以上はありません. これは非常にイライラするので、コードは少し面倒です。
private void startTrending_Click(object sender, EventArgs e)
{
// Disable all controls on the form
startTrending.Enabled = false;
// and only Enable the Stop button
stopTrending.Enabled = true;
// Predefine the viewing area of the chart
minValue = DateTime.Now;
maxValue = minValue.AddMinutes(120);
chart1.ChartAreas[0].AxisX.Minimum = minValue.ToOADate();
chart1.ChartAreas[0].AxisX.Maximum = maxValue.ToOADate();
// Reset number of series in the chart.
chart1.Series.Clear();
// create a line chart series
Series newSeries = new Series("Series1");
newSeries.ChartType = SeriesChartType.Line;
newSeries.BorderWidth = 2;
newSeries.Color = Color.OrangeRed;
newSeries.XValueType = ChartValueType.Time;
chart1.Series.Add(newSeries);
/*chart1.ChartAreas[0].AxisX.LabelStyle.Format = "hh:mm";
chart1.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.Minutes;
chart1.ChartAreas[0].AxisX.Interval = 1;
chart1.ChartAreas[0].AxisX.MajorGrid.Interval = 1;
chart1.ChartAreas[0].AxisX.MajorTickMark.Interval = 0.5;
chart1.ChartAreas[0].AxisX. */
chart1.ChartAreas[0].AxisX.ScrollBar.Enabled = true;
chart1.ChartAreas[0].AxisX.ScaleView.SizeType = DateTimeIntervalType.Minutes;
chart1.ChartAreas[0].AxisX.ScaleView.Size = 1;
chart1.ChartAreas[0].CursorX.Interval = 0;
// start worker threads.
if (addDataRunner.IsAlive == true)
{
addDataRunner.Resume();
}
else
{
addDataRunner.Start();
}
}