我正在从串口读取数据并以ms-chart控件显示。我只是不知道在我的图表区域中总共只有5个垂直条(相隔1秒) - >在我的图表区域中共有5秒钟的数据并且没有。在X轴上显示的秒数。
` timer = new Timer();
timer.Tick += Timer_Tick;
timer.Interval = 100;
chart1.ChartAreas[0].AxisY.Maximum = 1024;
chart1.ChartAreas["ChartArea1"].AxisY.MajorGrid.Enabled = false;
private void Timer_Tick(object sender, EventArgs e)
{
string data;
data = _port.ReadExisting();
var dataBlocks = data.Split('\n');
foreach (var block in dataBlocks)
{
var numbers = block.Split(new [] {' '}, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < numbers.Length; i++)
{
double n = double.NaN;
bool ok = double.TryParse(numbers[i], out n);
if (ok)
{
if (n > 30)
{
chart1.Series[i].Points.AddXY(x, n);
if (chart1.Series[0].Points.Count > 700)
chart1.Series[0].Points.RemoveAt(0);
}
}
}
}
}`