Page 1 of 1

While zooming chart annotation misplaced

Posted: Tue Mar 10, 2015 5:38 am
by 16071129
i placed annotation on my chart using following code

Code: Select all

 Steema.TeeChart.Tools.Annotation tAnnotation = new Steema.TeeChart.Tools.Annotation();
tAnnotation.Shape.Font.Color = Color.White;
tAnnotation.Shape.Font.Size = 10;
tAnnotation.Shape.Color = Color.Black;
tAnnotation.Text = strVal;
tAnnotation.Shape.CustomPosition = true;
tAnnotation.Shape.Left = e.X;
tAnnotation.Shape.Top = e.Y;
tAnnotation.Shape.Shadow.Visible = false;
tAnnotation.Shape.Transparent = true;
tChartMain.Tools.Add(tAnnotation);
after placing perfectly if i zoomed the chart then annotation is not following my chart zoom and actually moves away from series where i plotted it. Same this works well with Trendline tool without any problem for zoom.
I used following code for zooming

Code: Select all

tChartMain.Zoom.Active = true;
tChartMain.Zoom.Allow = true;
tChartMain.Zoom.Pen.Visible = true;
tChartMain.Zoom.Brush.Visible = true;
tChartMain.Zoom.MouseButton = MouseButtons.Left;
tChartMain.Zoom.Direction = ZoomDirections.Both;
tChartMain.Zoom.FullRepaint = true;
tChartMain.Zoom.Pen.Color = Color.White;
tChartMain.Zoom.Brush.Color = Color.White;
tChartMain.Zoom.Brush.Transparency = 100;
Kindly help me to get to the appropriate solution for this.

Re: While zooming chart annotation misplaced

Posted: Tue Mar 10, 2015 9:21 am
by Christopher
Quant,

You can achieve this by fixing the annotation position to the position of one of the series points, e.g.

Code: Select all

    Points series = new Points();
    Steema.TeeChart.Tools.Annotation tAnnotation = new Steema.TeeChart.Tools.Annotation();

    private void InitializeChart()
    {
      tChart1.Aspect.View3D = false;
      tChart1.Series.Add(series);
      series.FillSampleValues();

      tChart1.BeforeDrawSeries += tChart1_BeforeDrawSeries;
      
      tAnnotation.Shape.Font.Color = Color.White;
      tAnnotation.Shape.Font.Size = 10;
      tAnnotation.Shape.Color = Color.Black;
      tAnnotation.Text = "Annotation String";
      tAnnotation.Shape.CustomPosition = true;
      tAnnotation.Shape.Shadow.Visible = false;
      tAnnotation.Shape.Transparent = false;
      tChart1.Tools.Add(tAnnotation);
    }

    void tChart1_BeforeDrawSeries(object sender, Graphics3D g)
    {
      tAnnotation.Shape.Left = series.CalcXPos(5); //fix position to fifth point
      tAnnotation.Shape.Top = series.CalcYPos(5);
    }