如果你想在你的圖使用實際的日期時間值,這裏是如何設置它:
Series s = chart1.Series[0];
Axis ax = chart1.ChartAreas[0].AxisX;
s.ChartType = SeriesChartType.Line;
s.XValueType = ChartValueType.Time;
DateTime dt0 = DateTime.MinValue; // any date will do, just know which you use!
ax.Minimum = dt0.AddSeconds(0).ToOADate();
ax.Maximum = dt0.AddSeconds(600).ToOADate();
ax.Interval = 10;
ax.IntervalType = DateTimeIntervalType.Seconds;
ax.MajorGrid.Interval = 15;
ax.MajorGrid.IntervalType = DateTimeIntervalType.Seconds;
ax.MinorGrid.Interval = 5;
ax.MinorGrid.IntervalType = DateTimeIntervalType.Seconds;
ax.LabelStyle.Interval = 60;
ax.LabelStyle.IntervalType = DateTimeIntervalType.Seconds;
ax.LabelStyle.Format = "mm:ss";
for (int i = 0; i < 10; i++)
{
s.Points.AddXY(dt0.AddSeconds(rnd.Next(30) + 40 * i).ToOADate(), i);
}
這裏是結果:
你可以代替保留一切在數字領域;但你不能格式化x軸標籤的時間,也不直接在計算時間值使用x值,這可能會或可能不會是一個問題:
s.XValueType = ChartValueType.Int32;
ax.Minimum = 0;
ax.Maximum = 600;
ax.Interval = 10;
ax.IntervalType = DateTimeIntervalType.Number;
ax.MajorGrid.Interval = 15;
ax.MajorGrid.IntervalType = DateTimeIntervalType.Number;
ax.MinorGrid.Interval = 5;
ax.MinorGrid.IntervalType = DateTimeIntervalType.Number;
ax.LabelStyle.Interval = 60;
ax.LabelStyle.IntervalType = DateTimeIntervalType.Number;
來源
2016-10-02 11:21:18
TaW
感謝您的時間寫這個。雖然我得到溢出錯誤。我應該說,圖中的X軸是逐幀生成的。因此,10分鐘視頻中大約有4000幀。所以我想這是我要去錯的地方。 – user2924019
是的,可能。請注意,我如何通過將數據點添加到開始時間來創建數據點的時間值。如何添加數據點 – TaW
我的代碼循環遍歷視頻的每個幀,併爲每個幀生成運動值。我簡單地用下面的代碼將它添加到圖表中:'chart1.Series [「Series1」] .Points.AddY(valueToAdd);' – user2924019