Page 1 of 1

change color on a part of a line graph

Posted: Mon Apr 03, 2006 2:28 pm
by 9637396
Hi I have a line graph with about 100 points.
It is a red line
Now I want the line connecting point number 45, 46 and 47 to be green.
Is that possible? How?

Thanks in advance

Lars Iversen

Posted: Mon Apr 03, 2006 2:53 pm
by narcis
Hi Lars,

Yes, you have 2 options:

1) Setting the color when populating the series:

Code: Select all

    private void Form1_Load(object sender, EventArgs e)
    {
      Random rd = new Random();

      for (int i = 0; i < 100; i++)
      {
        if ((i>45) && (i<=47))
          line1.Add(rd.Next(),Color.Green);
        else
          line1.Add(rd.Next(),Color.Red);
      }
    }
2) Setting the color for the points you want doing something like:

Code: Select all

    private void button1_Click(object sender, EventArgs e)
    {
      line1.Colors[46] = Color.Green;
      line1.Colors[47] = Color.Green;
      line1.Repaint();
    }