Page 1 of 1

Remove text after drawing 2D text on canvas

Posted: Thu Aug 11, 2022 2:16 pm
by 15693683
Hi,

I wanted to add some custom text on a curve, depending on the points values.
I made a rocedure called in the afterdraw event of the chart, as follows :

Code: Select all

Public Sub label_water_valves(s As Steema.TeeChart.Styles.Series, e As Steema.TeeChart.Drawing.Graphics3DGdiPlus)
        Dim X, Y, old As Double
        Dim te = ""
        Dim res As Integer
        old = -1
        For i As Integer = 0 To s.XValues.Count - 1
            If s.YValues(i) > 0 And s.YValues(i) <> old Then
                X = Main.TChart1.Axes.Bottom.CalcXPosValue(s.XValues(i))
                Y = Main.TChart1.Axes.Left.CalcYPosValue(s.YValues(i))
                res = HexStringToBinary(s.YValues(i))
                If res And 4 Then te = te & "LP"
                If res And 16 Then te = te & vbCrLf & "HP"
                If res And 64 Then te = te & vbCrLf & "RSV"
                e.TextOut(X, Y, te)
                te = ""
                old = s.YValues(i)
            End If
        Next
    End Sub
    
s is the Serie I want to track.

Problem : once the text is drawn (works well), is there any way to hide it or remove it ?
In some part of my project, the user can hide/show curves. If I hide the series "s", the text remains on the graph...

The part 13 of the tutorial explains how to draw things on the graph, but not how to erase them.

Any idea ?

Thanks

Re: Remove text after drawing 2D text on canvas

Posted: Fri Aug 12, 2022 7:57 am
by Marc
Hello,

Everything in OnAfterDraw is called every time the Chart is rendered. If you put boolean conditions in there, like:

Code: Select all

if myCondition
  runCustomDrawCode
end if
then you can control i t being called by setting the condition to true or false ... Calling Chart.Repaint causes the chart to render and according to whether you have set the condition true/false the custom code will run or not; that way, effectively, removing any custom content if not required.

Regards,
Marc Meumann

Re: Remove text after drawing 2D text on canvas

Posted: Tue Aug 30, 2022 7:16 am
by 15693683
Hi !
Working fine ! Thanks for the answer.

Sharkann