Using GetPointerStyle event to apply different styles to line segments works incorrectly

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
bairog
Advanced
Posts: 128
Joined: Fri Dec 07, 2018 12:00 am

Using GetPointerStyle event to apply different styles to line segments works incorrectly

Post by bairog » Fri Sep 02, 2022 8:16 am

Hello. I've tried to use GetPointerStyle event to apply different styles to line segments as described here:

Code: Select all

private void Form1_Load(object sender, EventArgs e)
{
	var lineChart = new Line();
	lineChart.LinePen.Width = 2;
	lineChart.Pointer.Style = PointerStyles.Circle;
	lineChart.Pointer.Visible = true;

	tChart1.Series.Add(lineChart);

	lineChart.FillSampleValues(10);
	lineChart.GetPointerStyle += line_GetPointerStyle;
}


void line_GetPointerStyle(Steema.TeeChart.Styles.CustomPoint series, Steema.TeeChart.Styles.GetPointerStyleEventArgs e)
{
	if ((e.ValueIndex == 3) || (e.ValueIndex == 6))
		series.LinePen.Style = Steema.TeeChart.Drawing.DashStyle.Dash;
	else
		series.LinePen.Style = Steema.TeeChart.Drawing.DashStyle.Solid;
}
As you can see I want a segment that leads to point #3 and a segment that leads to point #6 to be dashed.
But as the result a segment that leads to point #5 and a segment that leads to point #8 is dashed:
Безымянный.png
Безымянный.png (30.76 KiB) Viewed 6074 times
I use Steema.TeeChart.NET 4.2022.05.26 on .NET 5.0 (that also reproduces with latest Steema.TeeChart.NET 4.2022.08.23).
Looks like a bug or am I missing something?

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

Re: Using GetPointerStyle event to apply different styles to line segments works incorrectly

Post by Christopher » Fri Sep 02, 2022 10:27 am

Hello,
bairog wrote:
Fri Sep 02, 2022 8:16 am
Looks like a bug or am I missing something?
In this particular case, I think the GetPointerStyle is not the best event to use—if you use the BeforeDrawPoint event you will obtain the results you expect:

Code: Select all

    private void InitializeChart()
    {
      var lineChart = new Line();
      lineChart.LinePen.Width = 2;
      lineChart.Pointer.Style = PointerStyles.Circle;
      lineChart.Pointer.Visible = true;

      tChart1.Series.Add(lineChart);

      lineChart.FillSampleValues(10);
      //lineChart.GetPointerStyle += line_GetPointerStyle;
      lineChart.BeforeDrawPoint += LineChart_BeforeDrawPoint;

      tChart1.Legend.Visible = false;
    }

    private void LineChart_BeforeDrawPoint(Series Series, BeforeDrawPointEventArgs e)
    {
      var series = (CustomPoint)Series;
      if ((e.ValueIndex == 3) || (e.ValueIndex == 6))
        series.LinePen.Style = Steema.TeeChart.Drawing.DashStyle.Dash;
      else
        series.LinePen.Style = Steema.TeeChart.Drawing.DashStyle.Solid;
    }
Screenshot from 2022-09-02 12-25-28.png
Screenshot from 2022-09-02 12-25-28.png (34.58 KiB) Viewed 6065 times
This is because the GetPointerStyle is specific to the pointer, and in the source-code is called after the line is drawn.
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

bairog
Advanced
Posts: 128
Joined: Fri Dec 07, 2018 12:00 am

Re: Using GetPointerStyle event to apply different styles to line segments works incorrectly

Post by bairog » Fri Sep 02, 2022 10:33 am

Thank you, BeforeDrawPoint event is working correctly. But but I'm still curious why GetPointerStyle event woks unexpected way?

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

Re: Using GetPointerStyle event to apply different styles to line segments works incorrectly

Post by Christopher » Fri Sep 02, 2022 10:47 am

bairog wrote:
Fri Sep 02, 2022 10:33 am
Thank you, BeforeDrawPoint event is working correctly. But but I'm still curious why GetPointerStyle event woks unexpected way?
In essence, what's happening is this (pseudo code)

Code: Select all

foreach (var point in series)
{
     void DrawPoint(Point point)
     {
          void DrawPointer(Point point)
          {
               DoDrawPointerEvent(point);
               /*draw the pointer*/
          }

          DoDrawPointEvent(point);
          DrawLine(point);
          DrawPointer(point);
     }
    
     DrawPoint(point);
}
So by the time we draw the pointer the line has already been drawn, meaning that changes to the ChartPen of the line won't be drawn until the next cycle.
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