Page 1 of 1

TChart versus Chart

Posted: Tue Oct 10, 2006 1:32 pm
by 9641603
Hi,

Either I got confused or I'm overworked or something... :?

When I get an event from an Annotation object, I can query the Chart object from the Annotation object - but how do I get the matching TChart object???

Best,
Michal Blazejczyk

Posted: Wed Oct 11, 2006 11:27 am
by narcis
Hi Michal,

In v2 there is no way to find the 'container' of the chart class. For v3, IChart, which is internal in the v2 sources, has been public and you'll be able to do something like this:

Code: Select all

      IChart iChart = annotation1.Chart.Parent as IChart;
      IContainer container = iChart.GetContainer();.

Posted: Wed Oct 11, 2006 9:21 pm
by 9641603
Hi,

What I would like to know is how to get a TChart from a Chart:

Code: Select all

TChart tChart = annotation1.Chart.???;
Best,
Michal

Posted: Fri Oct 13, 2006 2:12 pm
by narcis
Hi Michal,

This is not possible because annotation.Chart.Parent can be either a TChart or a WebChart. This is why IChart was published, IChart is an interface where TChart and WebChart inherit from. Once you get IChart you can obtain several properties as shown in the snippet above.

Posted: Mon Oct 16, 2006 3:48 pm
by 9641603
Hi,

OK, I see. But annotation.Chart.Parent doesn't exist. I guess it will be there in v3, right? And when it does, I should be able to cast annotation.Chart.Parent to TChart and that's it?

Best,
Michal

Posted: Tue Oct 17, 2006 10:35 am
by narcis
Hi Michal,

Yes, for example this will work:

Code: Select all

      Annotation anno1 = new Annotation(tChart1.Chart);
      anno1.Text = "hello";

      IChart ichart = anno1.Chart.Parent;
      TChart tchart;
      if (ichart is TChart)
      {
        tchart = ichart as TChart;
        tchart.Header.Text = "hello";
      }