Page 1 of 1

Color between points

Posted: Wed Mar 09, 2016 9:21 am
by 15677720
I have this test code

Code: Select all

            line1.Add(new DateTime(2016,1,1), 1);
            line1.Add(new DateTime(2016, 2, 1), 2);
            line1.Add(new DateTime(2016, 3, 1), 3, Color.Red);
            line1.Add(new DateTime(2016, 4, 1), 4, Color.Red);
            line1.Add(new DateTime(2016, 5, 1), 5);
Where I put two points in a different color. Then I see the line between second and third points is red although the second point is not red. How could I make teechart to change the color line only if both points are changed?

I mean in the example I would like only to be red the line between third and 4th points.

Thanks

Re: Color between points

Posted: Thu Mar 10, 2016 9:02 am
by Christopher
wakewakeup wrote: I mean in the example I would like only to be red the line between third and 4th points.
Okay, in which case you should be able to use code similar to the following:

Code: Select all

    private void InitializeChart()
    {
      tChart1.Aspect.View3D = false;
      Line line1 = new Line(tChart1.Chart);

      line1.Pointer.Visible = true;
      line1.Add(new DateTime(2016, 1, 1), 1);
      line1.Add(new DateTime(2016, 2, 1), 2);
      line1.Add(new DateTime(2016, 3, 1), 3);
      line1.Add(new DateTime(2016, 4, 1), 4, Color.Red);
      line1.Add(new DateTime(2016, 5, 1), 5);

      line1.GetPointerStyle += Line1_GetPointerStyle;
    }

    private void Line1_GetPointerStyle(CustomPoint series, GetPointerStyleEventArgs e)
    {
      if(e.ValueIndex == 2)
      {
        e.Color = Color.Red;
      }
    }

Re: Color between points

Posted: Thu Mar 10, 2016 3:53 pm
by 15677720
Thanks, it runs, but is a bit weird.

It is difficult to know in "Line1_GetPointerStyle" function dynamically which valueIndex was send without red colour because the previous point wasn't red, or because it has not to be red.

Is not there any other way to do it more directly?

Thanks

Re: Color between points

Posted: Fri Mar 11, 2016 9:57 am
by Christopher
wakewakeup wrote: It is difficult to know in "Line1_GetPointerStyle" function dynamically which valueIndex was send without red colour because the previous point wasn't red, or because it has not to be red.
Actually, this can be known in the event with code such as this:

Code: Select all

    private void InitializeChart()
    {
      tChart1.Aspect.View3D = false;
      Line line1 = new Line(tChart1.Chart);

      line1.Pointer.Visible = true;
      line1.Add(new DateTime(2016, 1, 1), 1);
      line1.Add(new DateTime(2016, 2, 1), 2);
      line1.Add(new DateTime(2016, 3, 1), 3);
      line1.Add(new DateTime(2016, 4, 1), 4, Color.Red);
      line1.Add(new DateTime(2016, 5, 1), 5);

      line1.GetPointerStyle += Line1_GetPointerStyle;
    }

    private void Line1_GetPointerStyle(CustomPoint series, GetPointerStyleEventArgs e)
    {
      if (series[e.ValueIndex + 1].Color == Color.Red)
      {
        e.Color = Color.Red;
      }
    }

Re: Color between points

Posted: Fri Mar 11, 2016 4:13 pm
by 15677720
Thanks it is a good trick. But still I don't find an easy way to put in red points which not have the previous and neither the next red so I don't want to have red line...

Isn't there any way to set the color of the line and de point independently?

Re: Color between points

Posted: Mon Mar 14, 2016 8:55 am
by Christopher
wakewakeup wrote:Isn't there any way to set the color of the line and de point independently?
Yes, you can set the global line and point colors like this:

Code: Select all

      line1.Color = Color.Green;
      line1.Pointer.Color = Color.Yellow;
The way to set *single* point color/characteristics rather than global point color/characteristics independently from the line is to use the GetPointerStyle event, which is what it was designed for.
wakewakeup wrote:But still I don't find an easy way to put in red points which not have the previous and neither the next red so I don't want to have red line...
I'm not sure I follow you here - to set a single point color without modifying the line color you can use:

Code: Select all

    private void InitializeChart()
    {
      tChart1.Aspect.View3D = false;
      Line line1 = new Line(tChart1.Chart);

      line1.Pointer.Visible = true;
      line1.Add(new DateTime(2016, 1, 1), 1);
      line1.Add(new DateTime(2016, 2, 1), 2);
      line1.Add(new DateTime(2016, 3, 1), 3);
      line1.Add(new DateTime(2016, 4, 1), 4);
      line1.Add(new DateTime(2016, 5, 1), 5);


      line1.GetPointerStyle += Line1_GetPointerStyle;
    }

    private void Line1_GetPointerStyle(CustomPoint series, GetPointerStyleEventArgs e)
    {
      if (e.ValueIndex == 2)
      {
        e.Color = Color.Red;
      }
    }