Page 1 of 1
How to display annotation text vertically.
Posted: Wed Jul 27, 2016 2:07 pm
by 13049533
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
Re: How to display annotation text vertically.
Posted: Thu Jul 28, 2016 9:09 am
by Christopher
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);
}
Re: How to display annotation text vertically.
Posted: Thu Jul 28, 2016 12:17 pm
by 13049533
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.
Re: How to display annotation text vertically.
Posted: Thu Jul 28, 2016 3:45 pm
by Christopher
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);
}
}
}
Re: How to display annotation text vertically.
Posted: Fri Jul 29, 2016 2:32 pm
by 13049533
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.
Re: How to display annotation text vertically.
Posted: Mon Aug 01, 2016 9:59 am
by 10050769
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
Re: How to display annotation text vertically.
Posted: Mon Aug 01, 2016 1:44 pm
by 13049533
Hi sandra,
Thanks for the help.
Regards,
Biji.