如何将数据放入图表中
问题描述:
我正在使用ZedGraph中的图表。我想把一些数据放在里面,我不知道如何。 我的数据每1minut由一个计时器来,他们是整数。关于Zedgraph的事情是,它必须是双倍的。那不是问题。我想要每隔1分钟建立一个图表,并且每隔1分钟就会在柱状图中添加一个新的柱状图。我的图有6个系列。 A-F。如何将数据放入图表中
DateTime dtime = DateTime.Now;
int a = ctrscan.analyzeNewScanQuality1A();
int b = ctrscan.analyzeNewScanQuality1B();
int c = ctrscan.analyzeNewScanQuality1C();
int D = ctrscan.analyzeNewScanQuality1D();
int e = ctrscan.analyzeNewScanQuality1E();
int f = ctrscan.analyzeNewScanQuality1F();
double time = Convert.ToDouble(dtime.Minute);
double[] y = { 90, 100, 95, 35, 80, 35 };
double[] y2 = { 90, 100, 95, 35, 80, 35 };
double[] y3 = { 80, 110, 65, 15, 54, 67 };
double[] y4 = { 120, 125, 100, 40, 105, 75 };
double[] y5 = { 20, 125, 100, 40, 105, 75 };
double[] y6 = { 220, 125, 100, 40, 105, 75 };
double[] x = {time};
BarItem myBar = myPane.AddBar("Quality A", x, y, Color.Red);
此图仅接受双打列表中的数字。正如你所看到的,每一个“y”代表我的一个A-F。列表中的数字只是随机数字,不适用。
正如你所看到的,我得到int中的数字。我知道如何转换,所以这不是问题。我的问题是:如何在图表中获取它? 我想把它放在图中,1分钟后,一整套新的整数将到达。然后我想要旧的集合,以及图中的新集合。 最后一行是给你看我如何控制我的系列。
我正在使用visual studio c#,并在winform内部打毛。
希望你明白!
答
public partial class Chart : Form
{
public Chart()
{
InitializeComponent();
}
private void SetSize()
{
zedGraphControl1.Location = new Point(10, 10);
// Leave a small margin around the outside of the control
zedGraphControl1.Size = new Size(ClientRectangle.Width - 20,
ClientRectangle.Height - 20);
}
private void Chart_Load(object sender, EventArgs e)
{
CreateGraph(zedGraphControl1);
SetSize();
}
private void CreateGraph(ZedGraphControl zg1)
{
GraphPane myPane = zedGraphControl1.GraphPane;
myPane.XAxis.Type = AxisType.Date;
PointPairList PPLa = new PointPairList();
PointPairList PPLb = new PointPairList();
PointPairList PPLc = new PointPairList();
PointPairList PPLd = new PointPairList();
PointPairList PPLe = new PointPairList();
PointPairList PPLf = new PointPairList();
int Max = 1;
for (int i = 0; i < Max; i++)
{
DateTime dtime = DateTime.Now;
//int a = ctrscan.analyzeNewScanQuality1A();
//int b = ctrscan.analyzeNewScanQuality1B();
//int c = ctrscan.analyzeNewScanQuality1C();
//int d = ctrscan.analyzeNewScanQuality1D();
//int e = ctrscan.analyzeNewScanQuality1E();
//int f = ctrscan.analyzeNewScanQuality1F();
int a = 1;
int b = 1;
int c = 2;
int d = 1;
int e = 3;
int f = 2;
double date = (double)new XDate(dtime);
PPLa.Add(date, (double)a);
PPLb.Add(date, (double)b);
PPLc.Add(date, (double)c);
PPLd.Add(date, (double)d);
PPLe.Add(date, (double)e);
PPLf.Add(date, (double)f);
BarItem myBara = myPane.AddBar("Bar A", PPLa, Color.Red);
BarItem myBarb = myPane.AddBar("Bar B", PPLb, Color.Blue);
BarItem myBarc = myPane.AddBar("Bar C", PPLc, Color.Green);
BarItem myBard = myPane.AddBar("Bar D", PPLd, Color.Black);
BarItem myBare = myPane.AddBar("Bar E", PPLe, Color.Yellow);
BarItem myBarf = myPane.AddBar("Bar F", PPLf, Color.Orange);
zedGraphControl1.AxisChange();
// sleep(1 minute);
}
zg1.AxisChange();
}
private void Chart_Resize(object sender, EventArgs e)
{
SetSize();
}
}
每分钟刷新一次你的图表,你需要重新绘制新的值。你需要自己弄清楚睡眠时间(1分钟)。
Form1加载时调用Chart_load
该图不显示'? –
可能没有足够的额外东西补充:你有一个zedgraphControl添加到你的表单,设计? 我用所有的东西为你做了一个编辑(即使是一个小样本来显示图表 – Moonlight
所以,你要我让这个在一个新的类别 而我在myPane出现错误。 XAxis.Type = AxisType.Date; 它希望我写myPane.XAxis.Type = ZedGrpah.AxisType.Date; –