下載ZedGraph之後
導入visual studio 2010
在visual studio 2010的工具箱,右鍵→選擇項目→在.NET FRAMEWORK的頁面下按瀏覽,找到ZedGraph.dll,加入後就可以在工具箱看到ZedGraphControl了
簡介
將ZedGraphControl拉近程式後,可以看到空的圖表,如果要看title、X axis、Y axis這幾個字樣不爽的話,我們可以透過以下的程式碼來修改
zedGraphControl1.GraphPane.Title.Text = "標題測試";
zedGraphControl1.GraphPane.XAxis.Title.Text = "X軸";
zedGraphControl1.GraphPane.YAxis.Title.Text = "Y軸";
接下來我們以長條圖和折線圖作範例
首先定義資料
double[] data1 = { 1, 3, 5, 7, 9, 11 };
double[] data2 = { 2, 4, 6, 8, 10, 12 };
double[] data3 = { 5, 2, 6, 7, 5, 2 };
長條圖
BarItem myBar; //長條圖
myBar = zedGraphControl1.GraphPane.AddBar("資料1", null, data1, Color.Red);
myBar.Bar.Fill = new Fill(Color.Red, Color.White, Color.Red);
myBar = zedGraphControl1.GraphPane.AddBar("資料2", null, data2, Color.Green);
myBar.Bar.Fill = new Fill(Color.Green, Color.White, Color.Green);
myBar = zedGraphControl1.GraphPane.AddBar("資料3", null, data3, Color.Purple);
myBar.Bar.Fill = new Fill(Color.Purple, Color.White, Color.Purple);
折線圖
LineItem myCurve; //折線圖
myCurve = zedGraphControl1.GraphPane.AddCurve("資料1", null, data1, Color.Red);
myCurve.Line.Fill = new Fill(Color.Red, Color.White, Color.Red);
myCurve = zedGraphControl1.GraphPane.AddCurve("資料2", null, data2, Color.Green);
myCurve.Line.Fill = new Fill(Color.Green, Color.White, Color.Green);
myCurve = zedGraphControl1.GraphPane.AddCurve("資料3", null, data3, Color.Purple);
myCurve.Line.Fill = new Fill(Color.Purple, Color.White, Color.Purple);
以上二選一,接下來設定座標軸資料、更新圖表,就可以畫出統計圖了!
string[] xTitle = { "1", "2", "3", "4", "5", "6" }; //X軸的刻度資料
zedGraphControl1.GraphPane.XAxis.Scale.TextLabels = xTitle;
zedGraphControl1.GraphPane.XAxis.Type = AxisType.Text;
zedGraphControl1.GraphPane.Chart.Fill = new Fill(Color.White, Color.FromArgb(255, 255, 166), 90F);
zedGraphControl1.GraphPane.Fill = new Fill(Color.FromArgb(250, 250, 255));
zedGraphControl1.AxisChange();
zedGraphControl1.Refresh();
如果要清除統計圖,可以這樣做
zedGraphControl1.GraphPane.CurveList.Clear();//把舊的圖資清掉
c#编程示例代码
回覆刪除使用位图绘制3D表面