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.
Annotation with styles
-
- Guru
- Posts: 1603
- Joined: Fri Nov 15, 2002 12:00 am
Re: Annotation with styles
Hello!
yes, there is a simple, although not obvious, hack you can use. Here's the MyAnnotation class:
And here it is used:
which gives me the following:
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);
}
}
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>";
}
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 |
Re: Annotation with styles
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:
Width is correct if I don't use bold:
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.
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.
Is this behaviour correct?
Thank you
Martin
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:
Width is correct if I don't use bold:
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.
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
Thank you
Martin
-
- Guru
- Posts: 1603
- Joined: Fri Nov 15, 2002 12:00 am
Re: Annotation with styles
Hello,
No - this is a small defect which I've entered into our issue tracking software with id=1723 and which I've already fixed.BMR wrote:Is this behaviour correct?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
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 |
-
- Guru
- Posts: 1603
- Joined: Fri Nov 15, 2002 12:00 am
Re: Annotation with styles
So setting this property to this value gives you the result you need, is that correct?BMR wrote: I set ClipText = false to see the whole text.
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 |
Re: Annotation with styles
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:
Martin
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:
Martin
-
- Guru
- Posts: 1603
- Joined: Fri Nov 15, 2002 12:00 am
Re: Annotation with styles
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.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:
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 |
Re: Annotation with styles
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
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