Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ZedGraph filling areas

I am using the ZedGraph control and want to fill one side of the graph function with some color and other side with other color.

 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?
like image 615
Sergey Avatar asked Feb 02 '11 20:02

Sergey


1 Answers

I'm not very clear on what you're asking - but hopefully the below will help. You said in comments

Can I fill some polygon area in Zedgraph?

So here's how...

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);

Results in

enter image description here

Hopefully this will point you in the right direction!

(Code in VB as requested via http://converter.telerik.com/ - no guarentee of the VB code working or even compiling!)

like image 69
dav_i Avatar answered Sep 28 '22 11:09

dav_i