Search code examples
c#iosteechart

How to set font in TextOut in AfterDraw event using MonoTouch and TeeChart


I am trying to add some custom text to my chart. However I have difficulties setting the font in Monotouch.

    ChartFont fontLine1 = new ChartFont();
    fontLine1.Brush.Color = Style.ColorStyle4;
    fontLine1.DrawingFont = Style.ValueItemTitle.ToCTFont();

    g.TextOut(fontLine1, currentX, currentY, AnnotationLabel);

Style.ColorStyle4 is White (CGColor); The .TOCTFont is a conversion routing to convert a UIFont to a CTFont.

However, the text is still small (size should be 18) and the font name is not correct.

If I don't set the ChartFont I get exactly the same result.

So, how to set proper font for writing text in AfterDraw event?


Solution

  • You can modify or add custom text (color, font, size) using the OnAfterDraw event. The code below shows you how can do it:

    private void chart_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
    {
        g.Font.Name = "Arial";
        g.Font.Color = UIColor.Red.CGColor;
        g.Font.Size = 18;
    
        g.TextOut(xpos, ypos, "label");
    }