How to display annotation text vertically.

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
biji
Newbie
Newbie
Posts: 35
Joined: Wed Jul 02, 2008 12:00 am

How to display annotation text vertically.

Post by biji » Wed Jul 27, 2016 2:07 pm

Hi,

I am trying to add some text description on the chart after drawing.

I don't know which is the best method?

I have tried with annotations. It was working but the text should place vertically not horizontally. I want to display the text from the point i clicked to either top or bottom direction.

Can anyone suggest me how to add text vertically on the chart? is it possible with annotations? If not how to add text on the chart vertically?

Code: Select all

 anSeries1 = new Steema.TeeChart.Tools.Annotation(mainTChart.Chart);
                    anSeries1.Text = text;
                    anSeries1.Shape.CustomPosition = true;
                    anSeries1.Shape.Font.Color = Color.Blue;
                    anSeries1.Shape.Font.Bold = true;
                    anSeries1.Shape.Left = e.X;             // get x, y position from mouse click.
                    anSeries1.Shape.Top = e.Y;
                    anSeries1.Shape.Pen.Visible = false;
                    anSeries1.Shape.Shadow.Visible = false;
                    anSeries1.Shape.Brush.Transparency = 100;
Regards,
biji

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

Re: How to display annotation text vertically.

Post by Christopher » Thu Jul 28, 2016 9:09 am

Hello,

The best method is to use the AfterDraw event, e.g.

Code: Select all

    private void InitializeChart()
    {
      tChart1.Aspect.View3D = false;
      tChart1.Series.Add(typeof(Line)).FillSampleValues();
      tChart1.AfterDraw += TChart1_AfterDraw;
    }

    private void TChart1_AfterDraw(object sender, Graphics3D g)
    {
      string s = "This Text";
      Rectangle rect = Utils.FromLTRB(200, 100, 220, 102 + Utils.Round(g.TextWidth(s)));
      g.Pen.Color = Color.Red;
      g.Brush.Color = Color.Yellow;

      g.Rectangle(rect);
      g.RotateLabel(rect.Left, rect.Bottom, s, 90);
    }
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

biji
Newbie
Newbie
Posts: 35
Joined: Wed Jul 02, 2008 12:00 am

Re: How to display annotation text vertically.

Post by biji » Thu Jul 28, 2016 12:17 pm

Hi,

Is there anyway that we can rotate annotation?

because it seems easy to place several texts on a mouse click point.

I am trying to add several texts on the chart. I would like to add text wherever i click mouse left.

With AfterDraw event i was able to create rectangle with text immediately after drawing chart but i want add text on the chart where i click mouse left.

The rectangle box with text appearing on the chart which covering the space so the background grid is not visible but i don't want like that i want text only, no rectangle shapes to visible and background grid should appear.

Regards,
Biji.
Last edited by biji on Mon Aug 01, 2016 1:45 pm, edited 2 times in total.

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

Re: How to display annotation text vertically.

Post by Christopher » Thu Jul 28, 2016 3:45 pm

Hello,

I'm afraid there is no property of the Annotation class that enables you to rotate it.

However, you can use the AfterDraw event and the MouseDown event to produce the same effect, e.g.

Code: Select all

    private void InitializeChart()
    {
      tChart1.Aspect.View3D = false;
      tChart1.Series.Add(typeof(Line)).FillSampleValues();
      tChart1.AfterDraw += TChart1_AfterDraw;
      tChart1.MouseDown += TChart1_MouseDown;
    }

    List<Point> rightClicks = new List<Point>();


    private void TChart1_MouseDown(object sender, MouseEventArgs e)
    {
      if (e.Button == MouseButtons.Right)
      {
        rightClicks.Add(e.Location);
        tChart1.Invalidate();
      }
    }

    private void TChart1_AfterDraw(object sender, Graphics3D g)
    {
      if(rightClicks.Count > 0)
      {
        foreach (Point rightClick in rightClicks)
        {
          string s = "This Text";
          Rectangle rect = Utils.FromLTRB(rightClick.X, rightClick.Y, rightClick.X + 20, rightClick.Y + 2 + Utils.Round(g.TextWidth(s)));
          g.RotateLabel(rect.Left, rect.Bottom, s, 90);
        }
      }
    }
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

biji
Newbie
Newbie
Posts: 35
Joined: Wed Jul 02, 2008 12:00 am

Re: How to display annotation text vertically.

Post by biji » Fri Jul 29, 2016 2:32 pm

Hi Christopher,

Thanks for the reply,

I have tried as you suggested but there is an issue.

The same text is repeating all the time. always latest text is replacing the old ones. for ex. point1 = "this text", point2= "next text" but when i enter second text the first text also changing with second.

I can understand that it is because of foreach loop.

I tried several ways but not succeeded even I have created a list for strings as well but no use.

I have to enter different text at different locations as i shown in the attached chart image.

Can you suggest me how to keep the old text as it is even after entering new text.

Regards,
Biji.

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: How to display annotation text vertically.

Post by Sandra » Mon Aug 01, 2016 9:59 am

Hello biji,

To fix the problem you're experiencing is needed use For loop instead of Foreach loop, therefore, I would suggest you change the AfterDraw event code for the code below:

Code: Select all

        private void TChart1_AfterDraw(object sender, Graphics3D g)
        {
            if (rightClicks.Count > 0)
            {
                for (int i = 0; i < rightClicks.Count; i++)
                {

                    string s = "Text:" + rightClicks[i].X;
                    Rectangle rect = Utils.FromLTRB(rightClicks[i].X, rightClicks[i].Y, rightClicks[i].X + 20, rightClicks[i].Y + 2 + Utils.Round(g.TextWidth(s)));
                    g.RotateLabel(rect.Left, rect.Bottom, s, 90);
                }
  
            }
        }
Hoping this helps you.
Thanks in advance
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

biji
Newbie
Newbie
Posts: 35
Joined: Wed Jul 02, 2008 12:00 am

Re: How to display annotation text vertically.

Post by biji » Mon Aug 01, 2016 1:44 pm

Hi sandra,

Thanks for the help.

Regards,
Biji.

Post Reply