Annotation with styles

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
BMR
Newbie
Newbie
Posts: 4
Joined: Mon May 30, 2016 12:00 am

Annotation with styles

Post by BMR » Wed Dec 14, 2016 11:38 am

Hello,
is there some way how to create Annotation with styled text? I think that it could be enough mix of normal and bold text. I have several lines in the Annotation and I want to stress the most important things.
can you please provide me some example how to do it?
I thought about creating my own Annotation class which inherits from yours and override painting, but it would be easier with some sample code from your side :-).
Thank you.

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

Re: Annotation with styles

Post by Christopher » Wed Dec 14, 2016 4:42 pm

Hello!

yes, there is a simple, although not obvious, hack you can use. Here's the MyAnnotation class:

Code: Select all

  public class MyAnnotation : Annotation
  {
    public MyAnnotation(Chart c) : base(c) { }

    protected override void DrawString(Graphics3D g, int x, int y, int t, int tmpHeight, string[] s)
    {
      g.TextOut(x, y + (t - 1) * tmpHeight, 0, s[t - 1], Shape.TextFormat == TextFormat.Html);
    }
  }
And here it is used:

Code: Select all

    private void InitializeChart()
    {
      MyAnnotation tool = new MyAnnotation(tChart1.Chart);
      tool.Shape.TextFormat = TextFormat.Html;
      tool.Shape.Font.Size = 20;
      tool.Text = "<b>Hello</b>" + Utils.NewLine + "<i>World</i>";
    }
which gives me the following:
636173338531141609.jpg
636173338531141609.jpg (18.98 KiB) Viewed 14186 times
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

BMR
Newbie
Newbie
Posts: 4
Joined: Mon May 30, 2016 12:00 am

Re: Annotation with styles

Post by BMR » Thu Dec 15, 2016 10:03 am

Hello Christopher,
thank you for your quick reply. I didn't notice that I had old version of TeeChart in that project (from 2013) and html was not working in that version - it even didn't have TextOut method with five parameters.

Now I have problem with auto width. If I have normal and bold text on one line, it calculates wrong width for the annotation:
Image
Width is correct if I don't use bold:
Image
I also notice that the problem starts with enough long normal text - if I wrote only "Long normal: Long bold text" it works as expected.
Image
I set ClipText = false to see the whole text.

When I changing to the newest TeeChart version I notice that if I create Theme without Chart in constructor and then call Apply with my Chart it throws NullReferenceException, but it worked in the old 2013 version. When I create Theme with new Chart() in constructor and then call Apply with my Chart it works as expected.

Code: Select all

new Steema.TeeChart.Themes.TeeChartTheme(new Chart()).Apply(chart); //this works
new Steema.TeeChart.Themes.TeeChartTheme().Apply(chart); //this worked only in older version and now throws NullReferenceException
Is this behaviour correct?

Thank you

Martin

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

Re: Annotation with styles

Post by Christopher » Thu Dec 15, 2016 11:50 am

Hello,
BMR wrote:

Code: Select all

new Steema.TeeChart.Themes.TeeChartTheme(new Chart()).Apply(chart); //this works
new Steema.TeeChart.Themes.TeeChartTheme().Apply(chart); //this worked only in older version and now throws NullReferenceException
Is this behaviour correct?
No - this is a small defect which I've entered into our issue tracking software with id=1723 and which I've already fixed.
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

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

Re: Annotation with styles

Post by Christopher » Thu Dec 15, 2016 11:51 am

BMR wrote: I set ClipText = false to see the whole text.
So setting this property to this value gives you the result you need, is that correct?
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

BMR
Newbie
Newbie
Posts: 4
Joined: Mon May 30, 2016 12:00 am

Re: Annotation with styles

Post by BMR » Thu Dec 15, 2016 11:58 am

Sorry, I didn't wrote it clearly.
Images I posted are what it looks like if I set ClipText = false. If I set ClipText = true, the size of the Annotation is same, but the text is clipped, so it looks like this:
Image

Martin

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

Re: Annotation with styles

Post by Christopher » Thu Dec 15, 2016 12:28 pm

BMR wrote:Sorry, I didn't wrote it clearly.
Images I posted are what it looks like if I set ClipText = false. If I set ClipText = true, the size of the Annotation is same, but the text is clipped, so it looks like this:
Okay, I see. Yes, there is an issue with this "hack" in which AutoSize is not sizing to the text, in which case you will have to set it to false and manually set the width and height. I have added an enhancement to our issue tracking software with id=1725 to deal with this.
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

BMR
Newbie
Newbie
Posts: 4
Joined: Mon May 30, 2016 12:00 am

Re: Annotation with styles

Post by BMR » Thu Dec 15, 2016 3:06 pm

I appreciate your quick help.
Since I only need to handle bold and normal text I also overrode CalcTempWidth(Graphics3D g, string tmp, out int NumLines) method and now it looks almost OK - still not quite sure why there is such a big space between normal and bold text, because there is only one space in the source text (and it looks like at least two in the Annotation) but I guess it doesn't matter.
Thank you.

Martin

Post Reply