2011-02-02 195 views
4

我正在使用ZedGraph控件,並希望用某種顏色填充圖形函數的一側,而用其他顏色填充另一側。ZedGraph填充區域

PointPairList list1 = new PointPairList(); 
list1.Add(0, 4); 
list1.Add(4, 0); 
LineItem myCurve = myPane.AddCurve("y(n)", list1, Color.Red, SymbolType.Diamond); 

//This filling bottom side. 
myCurve.Line.Fill = new Fill(Color.White, Color.FromArgb(113, 255, 0, 0), 90F); 

//How to fill the top side? 
+1

你就不能添加一個填爲整個圖表的背景,然後第二個,就像你一樣,爲填寫你的曲線?這應該夠了吧。或者,也許你頭腦上還有別的東西? – Gacek 2011-02-04 11:46:10

+0

其實我也喜歡你說的,但是我需要填充多條線交點(某些多邊形)形成的區域,我可以在Zed圖中填充一些多邊形區域嗎? – Sergey 2011-02-10 21:04:02

回答

5

我不是很清楚你在問什麼 - 但希望下面會有所幫助。你在評論中說

我可以在Zedgraph中填充一些多邊形區域嗎?

因此,這裏是在

enter image description here

希望如何...

var zed = new ZedGraph.ZedGraphControl { Dock = System.Windows.Forms.DockStyle.Fill }; 

var poly = new ZedGraph.PolyObj 
{ 
    Points = new[] 
    { 
     new ZedGraph.PointD(0, 0), 
     new ZedGraph.PointD(0.5, 1), 
     new ZedGraph.PointD(1, 0.5), 
     new ZedGraph.PointD(0, 0) 
    }, 
    Fill = new ZedGraph.Fill(Color.Blue), 
    ZOrder = ZedGraph.ZOrder.E_BehindCurves 
}; 

var poly1 = new ZedGraph.PolyObj 
{ 
    Points = new[] 
    { 
     new ZedGraph.PointD(1, 0), 
     new ZedGraph.PointD(0.25, 1), 
     new ZedGraph.PointD(0.5, 0), 
     new ZedGraph.PointD(1, 0) 
    }, 
    Fill = new ZedGraph.Fill(Color.Red), 
    ZOrder = ZedGraph.ZOrder.E_BehindCurves 
}; 

zed.GraphPane.AddCurve("Line", new[] { 0.0, 1.0 }, new[] { 0.0, 1.0 }, Color.Green); 
zed.GraphPane.GraphObjList.Add(poly1); 
zed.GraphPane.GraphObjList.Add(poly); 

結果這將指向你在正確的方向!

(通過http://converter.telerik.com/Code in VB as requested - !沒有VB代碼的工作,甚至編譯的機制保障)