Color between points

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
wakewakeup
Newbie
Newbie
Posts: 6
Joined: Fri Feb 19, 2016 12:00 am

Color between points

Post by wakewakeup » Wed Mar 09, 2016 9:21 am

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
Attachments
rojo.png
rojo.png (10.71 KiB) Viewed 9476 times

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Color between points

Post by Christopher » Thu Mar 10, 2016 9:02 am

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;
      }
    }
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

wakewakeup
Newbie
Newbie
Posts: 6
Joined: Fri Feb 19, 2016 12:00 am

Re: Color between points

Post by wakewakeup » Thu Mar 10, 2016 3:53 pm

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

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Color between points

Post by Christopher » Fri Mar 11, 2016 9:57 am

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;
      }
    }
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

wakewakeup
Newbie
Newbie
Posts: 6
Joined: Fri Feb 19, 2016 12:00 am

Re: Color between points

Post by wakewakeup » Fri Mar 11, 2016 4:13 pm

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?

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Color between points

Post by Christopher » Mon Mar 14, 2016 8:55 am

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;
      }
    }
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

Post Reply