Search code examples
c#chartszedgraph

Set Zedgraph line width of existing line


Is it possible to set width of existing Zedgraph line? Most examples I saw demonstrate following method:

LineItem myCurve1 = myPane.AddCurve("Sine Wave", spl1, Color.Blue, SymbolType.None);
myCurve1.Line.Width = 3.0F;

But as I see it can be done only at moment of adding new curve. Most obvious solution is to create List and add all curves there to access them later. I wonder is it right way or I am at wrong track?

UPDATE
My situation is following. I have several line curves and list of them in listBox. I want to make currently selected curve bold. That is why I need access to existing curves.


Solution

  • LineItem has constructors that support setting the line width, so you can create the curve first and then add it to your GraphPane, like this:

    LineItem myCurve1 = 
        new LineItem("Sine Wave", spl1, Color.Blue, SymbolType.None, 3.0f);
    myPane.CurveList.Add(myCurve1);
    

    Which approach to recommend is more a matter of taste, I think, but personally I prefer to initialize my object as much as possible before adding it to any collection.

    UPDATE If you later on would like to access your specific curve item, simply retrieve it from myPane.CurveList. The objects in CurveList are CurveItem:s, so you may need to cast to LineItem to modify line specific properties.

    example

    ((LineItem)zedGraphControl1.GraphPane.CurveList[1]).Line.Width = 3.0F;