背景/要求:VS中應用chart控制元件,橫坐標為實時時間,同時加入滾動軸scrollbar,資料量超過一定值,滾動軸壓縮。
問題:橫坐標不是時間格式時,能夠正常顯示。比如要求有20個資料時,滾動軸顯示并壓縮。但橫坐標改為時間Datetime格式,程式開始運行時就顯示scrollbar,并且要點擊一下才會顯示曲線。
chart控制元件初始化代碼:
chart1.ChartAreas[0].AxisX.ScaleView.Size = xvalue;
chart1.ChartAreas[0].AxisX.ScaleView.SizeType = DateTimeIntervalType.Seconds;
chart1.ChartAreas[0].AxisX.ScaleView.MinSize = 1;// 15;
chart1.ChartAreas[0].AxisX.ScaleView.MinSizeType = DateTimeIntervalType.Seconds;
chart1.ChartAreas[0].AxisX.ScaleView.SmallScrollMinSize = 1;
chart1.ChartAreas[0].AxisX.ScaleView.SmallScrollMinSizeType = DateTimeIntervalType.Seconds;
chart1.ChartAreas[0].AxisX.Interval = 1;//這個interval可以用來修改顯示間隔,因為上面設定單位為秒,這里間隔為0.5秒
chart1.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.Seconds;
chart1.ChartAreas[0].AxisX.LabelStyle.Format = "HH:mm:ss"; //x軸時間顯示格式為時:分:秒
X軸顯示的時間格式,HH為大寫時是24小時制,hh小寫時是12小時制
series屬性設定
chart1.Series.Clear();
Series newSeries = new Series("Series1");
newSeries.ChartType = SeriesChartType.Line; //曲線為折線
newSeries.BorderWidth = 2; //線寬2像素
newSeries.Color = System.Drawing.Color.Black; //黑色線
newSeries.IsVisibleInLegend = false; //不顯示線條導航項
newSeries.XValueType = ChartValueType.DateTime;
chart1.Series.Add(newSeries);
折線point添加代碼:
DT = DateTime.Now;
chart1.Series[0].Points.AddXY(DT, IntResult);
uj5u.com熱心網友回復:
UPUPUP轉載請註明出處,本文鏈接:https://www.uj5u.com/net/34603.html
標籤:C#
