How to implement dynamic marker functionality on a curve

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
yangxiuwei
Newbie
Newbie
Posts: 2
Joined: Mon Sep 23, 2024 12:00 am

How to implement dynamic marker functionality on a curve

Post by yangxiuwei » Tue Nov 12, 2024 7:58 am

I want to dynamically add some markers on the curve, similar to what is shown in the image below. How can I achieve this?
20241112155720.png
20241112155720.png (6.57 KiB) Viewed 2575 times

Marc
Site Admin
Site Admin
Posts: 1272
Joined: Thu Oct 16, 2003 4:00 am
Location: Girona
Contact:

Re: How to implement dynamic marker functionality on a curve

Post by Marc » Tue Nov 12, 2024 8:27 am

Hello,

Could you clarify what you mean by dynamic please? ... It is possible to use the OnAfterDraw event (see: tutorial) but you could add text according to mouse movements or data movements. The image you show suggests something related to Axis label location, whereupon you could use the GetAxisLabel event alone (see Axis tutorial) or to set the text and then plot the text in OnAfterDraw. Many options.

Regards,
Marc Meumann
Steema Support

yangxiuwei
Newbie
Newbie
Posts: 2
Joined: Mon Sep 23, 2024 12:00 am

Re: How to implement dynamic marker functionality on a curve

Post by yangxiuwei » Tue Nov 12, 2024 8:41 am

Dynamic markers can display marker text on the curve based on x-axis coordinate values. Ideally, they should also support zooming.

Marc
Site Admin
Site Admin
Posts: 1272
Joined: Thu Oct 16, 2003 4:00 am
Location: Girona
Contact:

Re: How to implement dynamic marker functionality on a curve

Post by Marc » Tue Nov 12, 2024 10:43 am

The applied example in the tutorial I linked shows you how to do that:

Code: Select all

private void Form1_Load(object sender, System.EventArgs e) { 
        tChart1.Aspect.View3D = false; 
        line1.FillSampleValues(20); 
} 
 
private void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g) { 
        if(tChart1.Series.Count > 0){ 
            if(tChart1.Series[0].Count > 10) { 
                Series s = tChart1.Series[0]; 
                int h = Convert.ToInt32(g.TextHeight("H")); 
                Point p1 = new Point(s.CalcXPos(3), s.CalcYPos(3)); 
                Point p2 = new Point(s.CalcXPos(10), s.CalcYPos(10)); 
                g.Pen.Color = Color.Blue; 
                g.Pen.Width = 2; 
                g.Pen.Style = System.Drawing.Drawing2D.DashStyle.Dash; 
                g.MoveTo(p1); 
                g.LineTo(p2, 0); 
                g.TextOut(p1.X, p1.Y - h, "Point value: " + s.YValues[3].ToString()); 
                g.TextOut(p2.X, p2.Y, "Point value: " + s.YValues[10].ToString()); 
                g.TextOut(p2.X, p2.Y + h, "Change is: " + Convert.ToString(s.YValues[3] - s.YValues[10])); 
            } 
        } 
} 
In this case it's taking series values "s.CalcXPos(3), s.CalcYPos(3)" but values could be extracted from axis scales in the same way, using the Calc...(various options) methods.

tChart1.Graphics3D.RotateLabel offers text at angles other than horizontal.

Regards,
Marc
Steema Support

Post Reply