Page 1 of 1

Annotation creation in code

Posted: Thu Sep 24, 2009 4:46 am
by 13048389
Version: 3.5.3498.27368
OS: Windows XP

Hi,
I am trying to create an annotation with a callout in code but are having trouble getting it to display.
I am after a annotation with no border, a gradient fill, and a shadow. The callout is to be red with no pointer. I have tried several variantions on the following code with no success (I get an white annotation with no callout or gradient fill).

Code: Select all

Steema.TeeChart.Tools.Annotation backgroundCurveLabel = new Steema.TeeChart.Tools.Annotation();
backgroundCurveLabel.Active = true;
backgroundCurveLabel.Text = tccManager.GetTCCName(backgroundCurveID);
backgroundCurveLabel.AutoSize = true;
backgroundCurveLabel.Callout.Visible = true;
backgroundCurveLabel.Callout.Style = PointerStyles.Nothing;
backgroundCurveLabel.Callout.XPosition = MainSeries.CalcXPos(this.MainSeries.Count / 2);
backgroundCurveLabel.Callout.YPosition = MainSeries.CalcYPos(this.MainSeries.Count / 2);
backgroundCurveLabel.Callout.Pen.Visible = true;
backgroundCurveLabel.Callout.Pen.Color = Color.Red;
backgroundCurveLabel.Callout.Pen.Width = 3;
		
backgroundCurveLabel.Left = this.MainSeries.CalcXPos(this.MainSeries.Count / 2) + 20;
backgroundCurveLabel.Top = this.MainSeries.CalcYPos(this.MainSeries.Count / 2) - 20;
backgroundCurveLabel.Shape.Brush.Gradient.StartColor = Color.Cornsilk;
backgroundCurveLabel.Shape.Brush.Gradient.Visible = true;	
backgroundCurveLabel.Shape.Pen.Visible = false;
			
parentChart.Tools.Add(backgroundCurveLabel);
Also, i have tried using the designer to create the code and whilst being displayed correctly in the design view, the property changes for the annotation and the callout are not being serialized, and not displayed at runtime.

TIA,
NojaPower

Re: Annotation creation in code

Posted: Thu Sep 24, 2009 10:37 am
by yeray
Hi NojaPower,

The following code seems to achieve what you want here:

Code: Select all

        public Form1()
        {
            InitializeComponent();
            InitializeChart();
        }

        Steema.TeeChart.Styles.FastLine fast1;
        Steema.TeeChart.Tools.Annotation annotation1;

        private void InitializeChart()
        {
            chartController1.Chart = tChart1;

            tChart1.Aspect.View3D = false;

            fast1 = new Steema.TeeChart.Styles.FastLine(tChart1.Chart);
            fast1.FillSampleValues();

            annotation1 = new Steema.TeeChart.Tools.Annotation(tChart1.Chart);
            annotation1.Text = "annotation1";
            annotation1.Callout.Style = Steema.TeeChart.Styles.PointerStyles.Nothing;
            annotation1.Callout.Arrow.Visible = true;
            annotation1.Callout.Arrow.Color = Color.Red;
            annotation1.Shape.Brush.Gradient.StartColor = Color.Cornsilk;
            annotation1.Shape.Brush.Gradient.Visible = true;
            annotation1.Shape.Pen.Visible = false;

            tChart1.AfterDraw += new Steema.TeeChart.PaintChartEventHandler(tChart1_AfterDraw);

            tChart1.Draw();
        }

        void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
        {
            annotation1.Callout.XPosition = fast1.CalcXPos(fast1.Count / 2);
            annotation1.Callout.YPosition = fast1.CalcYPos(fast1.Count / 2);
            annotation1.Left = fast1.CalcXPos(fast1.Count / 2) + 20;
            annotation1.Top = fast1.CalcYPos(fast1.Count / 2) - 20;
        }

Re: Annotation creation in code

Posted: Thu Sep 24, 2009 9:55 pm
by 13048389
Hi Yeray,
Why do you need to re-initialise the values after each draw of the chart? Why can it not be performed during the initialise component.

Cheers,
NojaPower

Re: Annotation creation in code

Posted: Fri Sep 25, 2009 10:29 am
by yeray
Hi NojaPower,

Excuse me, only the position should be set each time in this example to allow chart scroll/zoom.
I've now corrected the code.

Re: Annotation creation in code

Posted: Tue Sep 29, 2009 12:06 am
by 13048389
Hi Yeray,
The key line i take it is:
annotation1.Callout.Arrow.Visible = true;

Without this the callout is not drawn. For mind, it is a little misleading - if you did not want to have an arrow visible you would not set this value to true.

Cheers,
NojaPower