C# chart里加了多条曲线, 为什么只显示最后一条 30
代码如下:privatevoiddisplayLines(stringdirName){ints=comboBox1.SelectedIndex;PulseBufferb...
代码如下:
private void displayLines(string dirName)
{
int s = comboBox1.SelectedIndex;
PulseBuffer buf = readData(s, dirName + "\\");
if (buf == null)
return;
chart1.Series.Clear();
ListBox.SelectedObjectCollection sels = comboBoxEx1.SelectedItems;
string[] ITEMS = { "通道1", "通道2", "通道3", "通道4", "通道5", "通道6" };
foreach (string item in sels)
{
// 找到选择的项
int selIndex = -1;
for (int i = 0; i < ITEMS.Length; i++)
{
if (item == ITEMS[i])
{
selIndex = i;
break;
}
}
if (selIndex == -1)
continue;
DisplayOneLine(buf, selIndex + 1);
}
}
// 显示一条曲线
public void DisplayOneLine(PulseBuffer buf, int trackNo)
{
Series series = new Series("通道"+trackNo) ;
series.ChartType = SeriesChartType.Line;
int t = 1;
for (int i = 0; i < buf.getLength(t); i++)
{
double x = buf.getSN(t, i);
double y = buf.getValue(t, i);
series.Points.AddXY(x, y);
}
chart1.Series.Add(series);
// Zoom into the X axis
chart1.ChartAreas[0].AxisX.ScaleView.Zoom(0, 400);
// Enable range selection and zooming end user interface
chart1.ChartAreas[0].CursorX.IsUserEnabled = true;
chart1.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
chart1.ChartAreas[0].AxisX.ScaleView.Zoomable = true;
//将滚动内嵌到坐标轴中
chart1.ChartAreas[0].AxisX.ScrollBar.IsPositionedInside = true;
// 设置滚动条的大小
chart1.ChartAreas[0].AxisX.ScrollBar.Size = 20;
// 设置滚动条的按钮的风格,下面代码是将所有滚动条上的按钮都显示出来
//chart1.ChartAreas[0].AxisX.ScrollBar.ButtonStyle = ScrollBarButtonStyle.All;
// 设置自动放大与缩小的最小量
chart1.ChartAreas[0].AxisX.ScaleView.SmallScrollSize = double.NaN;
chart1.ChartAreas[0].AxisX.ScaleView.SmallScrollMinSize = 30;
double max, min;
buf.getMaxMinValue(trackNo, out min, out max);
chart1.ChartAreas[0].AxisY.Minimum = min;
chart1.ChartAreas[0].AxisY.Maximum = max;
chart1.Visible = true;
}
设断点看chart1里面的Series已经有6个了,Y坐标也在范围内,为什么总是只显示最后一条呢?
运行结果如图 展开
private void displayLines(string dirName)
{
int s = comboBox1.SelectedIndex;
PulseBuffer buf = readData(s, dirName + "\\");
if (buf == null)
return;
chart1.Series.Clear();
ListBox.SelectedObjectCollection sels = comboBoxEx1.SelectedItems;
string[] ITEMS = { "通道1", "通道2", "通道3", "通道4", "通道5", "通道6" };
foreach (string item in sels)
{
// 找到选择的项
int selIndex = -1;
for (int i = 0; i < ITEMS.Length; i++)
{
if (item == ITEMS[i])
{
selIndex = i;
break;
}
}
if (selIndex == -1)
continue;
DisplayOneLine(buf, selIndex + 1);
}
}
// 显示一条曲线
public void DisplayOneLine(PulseBuffer buf, int trackNo)
{
Series series = new Series("通道"+trackNo) ;
series.ChartType = SeriesChartType.Line;
int t = 1;
for (int i = 0; i < buf.getLength(t); i++)
{
double x = buf.getSN(t, i);
double y = buf.getValue(t, i);
series.Points.AddXY(x, y);
}
chart1.Series.Add(series);
// Zoom into the X axis
chart1.ChartAreas[0].AxisX.ScaleView.Zoom(0, 400);
// Enable range selection and zooming end user interface
chart1.ChartAreas[0].CursorX.IsUserEnabled = true;
chart1.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
chart1.ChartAreas[0].AxisX.ScaleView.Zoomable = true;
//将滚动内嵌到坐标轴中
chart1.ChartAreas[0].AxisX.ScrollBar.IsPositionedInside = true;
// 设置滚动条的大小
chart1.ChartAreas[0].AxisX.ScrollBar.Size = 20;
// 设置滚动条的按钮的风格,下面代码是将所有滚动条上的按钮都显示出来
//chart1.ChartAreas[0].AxisX.ScrollBar.ButtonStyle = ScrollBarButtonStyle.All;
// 设置自动放大与缩小的最小量
chart1.ChartAreas[0].AxisX.ScaleView.SmallScrollSize = double.NaN;
chart1.ChartAreas[0].AxisX.ScaleView.SmallScrollMinSize = 30;
double max, min;
buf.getMaxMinValue(trackNo, out min, out max);
chart1.ChartAreas[0].AxisY.Minimum = min;
chart1.ChartAreas[0].AxisY.Maximum = max;
chart1.Visible = true;
}
设断点看chart1里面的Series已经有6个了,Y坐标也在范围内,为什么总是只显示最后一条呢?
运行结果如图 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询