求助!! 定时器绘制图表,如何改能让图表数据的Y值分别对应定义的随机变量,总是同一组数据
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
namespace RealChart
{
public partial class RealChart : Form
{
private Queue<double> dataQueue = new Queue<double>(100);
private Queue<double> datbQueue = new Queue<double>(100);
private Queue<double> datcQueue = new Queue<double>(100);
private Queue<double> datdQueue = new Queue<double>(100);
private Queue<double> dateQueue = new Queue<double>(100);
private Queue<double> datfQueue = new Queue<double>(100);
private int curValue = 0;
private int cuaValue = 0;
private int cubValue = 0;
private int cucValue = 0;
private int cudValue = 0;
private int cueValue = 0;
private int num = 5;//每次删除增加几个点
public RealChart()
{
this.skinEngine1 = new Sunisoft.IrisSkin.SkinEngine(((System.ComponentModel.Component)(this)));
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
UpdataQueueValue();
this.chart1.Series[0].Points.Clear();
for (int i = 0; i < dataQueue.Count; i++)
{
this.chart1.Series[0].Points.AddXY((i + 1), dataQueue .ElementAt(i));
}
UpdatbQueueValue();
this.chart2.Series[0].Points.Clear();
for (int v = 0; v < datbQueue.Count; v++)
{
this.chart2.Series[0].Points.AddXY((v + 1), datbQueue.ElementAt(v));
}
UpdatcQueueValue();
this.chart3.Series[0].Points.Clear();
for (int v = 0; v < datcQueue.Count; v++)
{
this.chart3.Series[0].Points.AddXY((v + 1), dataQueue.ElementAt(v));
}
UpdatdQueueValue();
this.chart4.Series[0].Points.Clear();
for (int v = 0; v < datdQueue.Count; v++)
{
this.chart4.Series[0].Points.AddXY((v + 1), datdQueue.ElementAt(v));
}
UpdateQueueValue();
this.chart5.Series[0].Points.Clear();
for (int v = 0; v < dateQueue.Count; v++)
{
this.chart5.Series[0].Points.AddXY((v + 1), dateQueue.ElementAt(v));
}
UpdatfQueueValue();
this.chart6.Series[0].Points.Clear();
for (int v = 0; v < datfQueue.Count; v++)
{
this.chart6.Series[0].Points.AddXY((v + 1), datfQueue.ElementAt(v));
}
}
private void btnInit_Click(object sender, EventArgs e)
{
InitChart();
}
private void btnStart_Click(object sender, EventArgs e)
{
this.timer1.Start();
}
private void btnStop_Click(object sender, EventArgs e)
{
this.timer1.Stop();
}
private void InitChart() {
//定义图表区域
this.chart1.ChartAreas.Clear();
ChartArea chartArea1 = new ChartArea("C1");
this.chart1.ChartAreas.Add(chartArea1);
this.chart2.ChartAreas.Clear();
ChartArea chartArea2 = new ChartArea("C2");
this.chart2.ChartAreas.Add(chartArea2);
this.chart3.ChartAreas.Clear();
ChartArea chartArea3 = new ChartArea("C3");
this.chart3.ChartAreas.Add(chartArea3);
this.chart4.ChartAreas.Clear();
ChartArea chartArea4 = new ChartArea("C4");
this.chart4.ChartAreas.Add(chartArea4);
this.chart5.ChartAreas.Clear();
ChartArea chartArea5 = new ChartArea("C5");
this.chart5.ChartAreas.Add(chartArea5);
this.chart6.ChartAreas.Clear();
ChartArea chartArea6 = new ChartArea("C6");
this.chart6.ChartAreas.Add(chartArea6);
this.chart1.Series.Clear();
Series series1 = new Series("S1");
series1.ChartArea = "C1";
this.chart1.Series.Add(series1);
this.chart2.Series.Clear();
Series series2 = new Series("S2");
series2.ChartArea = "C2";
this.chart2.Series.Add(series2);
this.chart3.Series.Clear();
Series series3 = new Series("S3");
series3.ChartArea = "C3";
this.chart3.Series.Add(series3);
this.chart4.Series.Clear();
Series series4 = new Series("S4");
series4.ChartArea = "C4";
this.chart4.Series.Add(series4);
this.chart5.Series.Clear();
Series series5 = new Series("S5");
series5.ChartArea = "C5";
this.chart5.Series.Add(series5);
this.chart6.Series.Clear();
Series series6 = new Series("S6");
series6.ChartArea = "C6";
this.chart6.Series.Add(series6);
//设置图表显示样式
this.chart1.ChartAreas[0].AxisY.Minimum = 0;
this.chart1.ChartAreas[0].AxisY.Maximum =100;
this.chart1.ChartAreas[0].AxisX.Interval = 5;
this.chart1.ChartAreas[0].AxisX.MajorGrid.LineColor = System.Drawing.Color.Silver;
this.chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = System.Drawing.Color.Silver;
this.chart2.ChartAreas[0].AxisY.Minimum = 0;
this.chart2.ChartAreas[0].AxisY.Maximum = 100;
this.chart2.ChartAreas[0].AxisX.Interval = 5;
this.chart2.ChartAreas[0].AxisX.MajorGrid.LineColor = System.Drawing.Color.Silver;
this.chart2.ChartAreas[0].AxisY.MajorGrid.LineColor = System.Drawing.Color.Silver;
this.chart3.ChartAreas[0].AxisY.Minimum = 0;
this.chart3.ChartAreas[0].AxisY.Maximum = 100;
this.chart3.ChartAreas[0].AxisX.Interval = 5;
this.chart3.ChartAreas[0].AxisX.MajorGrid.LineColor = System.Drawing.Color.Silver;
this.chart3.ChartAreas[0].AxisY.MajorGrid.LineColor = System.Drawing.Color.Silver;
this.chart4.ChartAreas[0].AxisY.Minimum = 0;
this.chart4.ChartAreas[0].AxisY.Maximum = 100;
this.chart4.ChartAreas[0].AxisX.Interval = 5;
this.chart4.ChartAreas[0].AxisX.MajorGrid.LineColor = System.Drawing.Color.Silver;
this.chart4.ChartAreas[0].AxisY.MajorGrid.LineColor = System.Drawing.Color.Silver;
this.chart5.ChartAreas[0].AxisY.Minimum = 0;
this.chart5.ChartAreas[0].AxisY.Maximum = 100;
this.chart5.ChartAreas[0].AxisX.Interval = 5;
this.chart5.ChartAreas[0].AxisX.MajorGrid.LineColor = System.Drawing.Color.Silver;
this.chart5.ChartAreas[0].AxisY.MajorGrid.LineColor = System.Drawing.Color.Silver;
this.chart6.ChartAreas[0].AxisY.Minimum = 0;
this.chart6.ChartAreas[0].AxisY.Maximum = 100;
this.chart6.ChartAreas[0].AxisX.Interval = 5;
this.chart6.ChartAreas[0].AxisX.MajorGrid.LineColor = System.Drawing.Color.Silver;
this.chart6.ChartAreas[0].AxisY.MajorGrid.LineColor = System.Drawing.Color.Silver;
//设置图表显示样式
this.chart1.Series[0].Color = Color.Red;
this.chart2.Series[0].Color = Color.Yellow;
this.chart3.Series[0].Color = Color.Purple;
this.chart4.Series[0].Color = Color.Brown;
this.chart5.Series[0].Color = Color.DarkSlateGray;
this.chart6.Series[0].Color = Color.Green;
if (rb1.Checked)
{
this.chart1.Series[0].ChartType = SeriesChartType.Line;
this.chart2.Series[0].ChartType = SeriesChartType.Line;
this.chart3.Series[0].ChartType = SeriesChartType.Line;
this.chart4.Series[0].ChartType = SeriesChartType.Line;
this.chart5.Series[0].ChartType = SeriesChartType.Line;
this.chart6.Series[0].ChartType = SeriesChartType.Line;
}
if (rb2.Checked) {
this.chart1.Series[0].ChartType = SeriesChartType.Spline;
this.chart2.Series[0].ChartType = SeriesChartType.Spline;
this.chart3.Series[0].ChartType = SeriesChartType.Spline;
this.chart4.Series[0].ChartType = SeriesChartType.Spline;
this.chart5.Series[0].ChartType = SeriesChartType.Spline;
this.chart6.Series[0].ChartType = SeriesChartType.Spline;
}
this.chart1.Series[0].Points.Clear();
this.chart2.Series[0].Points.Clear();
this.skinEngine1.SkinFile = Application.StartupPath + "//DiamondBlue.ssk";
}
//更新队列中的值
private void UpdataQueueValue()
{
if (dataQueue.Count > 100)
{
//先出列
for (int i = 0; i < num; i++)
{
dataQueue.Dequeue();
}
}
}
private void UpdatbQueueValue()
{
if (datbQueue.Count > 100) {
//先出列
for (int i = 0; i < num; i++)
{
datbQueue.Dequeue();
}
}
}
private void UpdatcQueueValue()
{
if (datcQueue.Count > 100)
{
for (int i = 0; i < num; i++)
{
datcQueue.Dequeue();
}
}
}
private void UpdatdQueueValue()
{
if (datdQueue.Count > 100)
{
for (int i = 0; i