如何以编程方式添加ZedGraph?

时间:2012-03-28 06:51:02

标签: c# winforms visual-studio-2010 zedgraph

我想在单击按钮时添加ZedGraph,但单击按钮时ZedGraph不会出现。这是我的按钮点击处理程序:

 ZedGraphControl zg1 = new ZedGraphControl(); 
 zg1.Dock = DockStyle.Fill;
 GraphPane myPane = new GraphPane();
 BarItem myBar = new BarItem("Bar1");
 myBar.AddPoint(1, 10);
 myBar.AddPoint(2, 20);
 myBar.Bar.Fill = new Fill(Color.AliceBlue, Color.White, Color.AliceBlue);
 zg1.AxisChange();
 zg1.Invalidate();

 zg1.Show();

1 个答案:

答案 0 :(得分:2)

向我突出的主要事情是,我没有看到你adding your new Control到你的容器对象,而是FormPanel。您也没有将PaneBarZedGraphControl

相关联

尝试类似这样的事情

ZedGraphControl zg1 = new ZedGraphControl();
zg1.Dock = DockStyle.Fill;
zg1.GraphPane = new GraphPane();

BarItem myBar = new BarItem("Bar1");
myBar.AddPoint(1, 10);
myBar.AddPoint(2, 20);
myBar.Bar.Fill = new Fill(Color.AliceBlue, Color.White, Color.AliceBlue);

zg1.GraphPane.CurveList.Add(myBar);


zg1.AxisChange();
zg1.Invalidate();

zg1.Show();
this.Controls.Add(zg1);