0

I'd like to populate a Zedgraph Pane with multiple graphs from a listbox with multiple curves. My method currently populates these curves, but they all have the same color and symbol type. Any suggestions on having each added curve be assigned a different color?

public void btnMakePlt_Click(object sender, EventArgs e)
    {
        try
        {
            // Initialize graph window

            GraphPane myPane = zgcMain.GraphPane;

            // clear plt

            myPane.CurveList.Clear();

            zgcMain.Refresh();

            // Use this foreach to plot curves in the Selected Curves Listbox

            foreach (var item2 in lstSelectedCurves.Items)
            {

                // turn CurveName into String

                txtCurve = item2.ToString();

                //Invoke IPmathCurveMethods, populate List 

                PointPairList list = new PointPairList();

                double[] CurveDataVal = PlotIPdataStuffValues(txtCurve);
                double[] CurveDataDepth = PlotIPdataStuffDepths(txtCurve);


                for (int i = 0; i < CurveDataVal.Length; i++)
                {

                    double z1 = CurveDataDepth[i];
                    double z2 = CurveDataVal[i];

                    if (z2 <= 0)
                    {
                        z2 = double.NaN;
                    }

                    //add to list

                    list.Add(z2, z1);

                }

                LineItem myCurve = myPane.AddCurve(txtCurve, list, Color.Red, SymbolType.None);

                zgcMain.Refresh();

            }

        }

        catch (Exception ex)
        {
            MessageBox.Show("Error making your plot \n" + ex.Message + "\n" + ex.StackTrace);
        }
    }

1 Answers1

0

You can either set up a list of colors that you select and use it in your foreach loop or you can use the auto color rotator provided in zedgraph as shown below. Note that there's a limit to the range of colors and it will loop back.

// Use this foreach to plot curves in the Selected Curves Listbox

var colorRotator = new ColorSymbolRotator();

var currentColor = Color.Black;

foreach (var item2 in lstSelectedCurves.Items)
{

    // turn CurveName into String

    txtCurve = item2.ToString();

    //Invoke IPmathCurveMethods, populate List 

    PointPairList list = new PointPairList();

    double[] CurveDataVal = PlotIPdataStuffValues(txtCurve);
    double[] CurveDataDepth = PlotIPdataStuffDepths(txtCurve);


    for (int i = 0; i < CurveDataVal.Length; i++)
    {

        double z1 = CurveDataDepth[i];
        double z2 = CurveDataVal[i];

        if (z2 <= 0)
        {
            z2 = double.NaN;
        }

        //add to list

        list.Add(z2, z1);

    }

    LineItem myCurve = myPane.AddCurve(txtCurve, list, currentColor, SymbolType.None);

    currentColor = colorRotator.NextColor;

    zgcMain.Refresh();

}

You can reset the color rotator at any point if, say you want to repeat only a set number of color changes and re-use those. I think that the first color is black (index = 0) by default.

colorRotator.NextColorIndex = 0;

dlr
  • 41
  • 3