I have a TDBChart (Bar) configured with one TSeriesAnimationTool to make the animation of the bars growing. I would like that this animation to be executed when the DBChart is paiting for the first time.
Is this possible?
I tried several ways, but none worked as I expected. Looks like the chart is always fully drawn before the animation is started.
Am I missing something?
PS: Note that the form has 5 graphics linked to 5 different datasets that are opened in sequence. The simplest code is like this:
Top5.Close;
Top5.ParamByName('dia1').AsDate:=Inic.Date;
Top5.ParamByName('dia2').AsDate:=Fim.Date;
Top5.Open;
ChartAnimation1.Execute; <- Animation starts, but the chart was already drawn
Low5.Close;
Low5.ParamByName('dia1').AsDate:=Inic.Date;
Low5.ParamByName('dia2').AsDate:=Fim.Date;
Low5.Open;
etc...
Thanks!
Carlos
How to execute the animation when chart is first drawn?
-
- Newbie
- Posts: 33
- Joined: Thu Mar 18, 2004 5:00 am
- Location: Brasil
- Contact:
Re: How to execute the animation when chart is first drawn?
Hi Carlos,
I've made a simple example using a TBarSeries with sample values and a TSeriesAnimationTool and it seems to work fine for me here:
Note I've added a chart repaint after populating the series. This is basically to force the axes to be scaled to fit the values in the series.
I've made a simple example using a TBarSeries with sample values and a TSeriesAnimationTool and it seems to work fine for me here:
Code: Select all
uses Series, TeeAnimations;
procedure TForm1.FormCreate(Sender: TObject);
begin
Chart1.AddSeries(TBarSeries).FillSampleValues;
Chart1.Draw;
with Chart1.Tools.Add(TSeriesAnimationTool) as TSeriesAnimationTool do
begin
Series:=Chart1[0];
Play;
end;
end;
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
-
- Newbie
- Posts: 33
- Joined: Thu Mar 18, 2004 5:00 am
- Location: Brasil
- Contact:
Re: How to execute the animation when chart is first drawn?
Thanks for replying!
I found a way to do what I want (well, almost...). The problem is that I have 5 DBcharts attached to 5 different datasets. The datasets are opened in sequence, and each of them takes some time to fetch the records, and this mess with the animation (probably because animation runs in low thread priority?).
What I did to solve the problem was to use Disable/EnableControls, something like this:
query1.disablecontrols;
query2.disablecontrols;
...
query1.open;
query2.open;
...
query1.enablecontrols;
query2.enablecontrols;
...
DBChart1.draw;
Animation1.play;
DBChart2.draw;
Animation2.play;
BUT, if I don't call the draw method before playing the animations, it gets really weird. But it is a bit nonsense to have the full chart draw to the screen and after that get the bars animated. Isn't there a way to "prepare" the chart without drawing it, just before playing the animation?
Carlos
I found a way to do what I want (well, almost...). The problem is that I have 5 DBcharts attached to 5 different datasets. The datasets are opened in sequence, and each of them takes some time to fetch the records, and this mess with the animation (probably because animation runs in low thread priority?).
What I did to solve the problem was to use Disable/EnableControls, something like this:
query1.disablecontrols;
query2.disablecontrols;
...
query1.open;
query2.open;
...
query1.enablecontrols;
query2.enablecontrols;
...
DBChart1.draw;
Animation1.play;
DBChart2.draw;
Animation2.play;
BUT, if I don't call the draw method before playing the animations, it gets really weird. But it is a bit nonsense to have the full chart draw to the screen and after that get the bars animated. Isn't there a way to "prepare" the chart without drawing it, just before playing the animation?
Carlos
Re: How to execute the animation when chart is first drawn?
Hello Carlos,
You could try to calculate the maximum and minimum values the axes will have when the animation will be completed and set them to the axes. Ie:
In your case this means you will probably have to calculate the min and max before disabling the datasets, before assigning them to the series.
You could try to calculate the maximum and minimum values the axes will have when the animation will be completed and set them to the axes. Ie:
Code: Select all
uses Series, TeeAnimations;
procedure TForm1.FormCreate(Sender: TObject);
begin
Chart1.Legend.Visible:=false;
Chart1.AddSeries(TBarSeries).FillSampleValues;
Chart1.Axes.Left.SetMinMax(0,Chart1[0].YValues.MaxValue);
Chart1.Axes.Bottom.SetMinMax(-0.5,Chart1[0].XValues.MaxValue+0.5);
with Chart1.Tools.Add(TSeriesAnimationTool) as TSeriesAnimationTool do
begin
Series:=Chart1[0];
Play;
end;
Chart1.Axes.Left.Automatic:=true;
Chart1.Axes.Bottom.Automatic:=true;
end;
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
-
- Newbie
- Posts: 33
- Joined: Thu Mar 18, 2004 5:00 am
- Location: Brasil
- Contact:
Re: How to execute the animation when chart is first drawn?
This hack seems to have solved my problem:
Anyway, I still think animations could be improved. For example, you could add a property telling the chart to autoplay the animation when it is drawing for the first time, meaning the first draw would already be done by the animation (no flickering at all).
Carlos
Code: Select all
SendMessage(parent.Handle, WM_SETREDRAW, WPARAM(False), 0);
try
DBChart1.Draw;
DBChart2.Draw;
DBChart3.Draw;
DBChart5.Draw;
finally
SendMessage(parent.Handle, WM_SETREDRAW, WPARAM(true), 0);
end;
DBChart1.Animations[0].Play;
DBChart2.Animations[0].Play;
DBChart3.Animations[0].Play;
DBChart5.Animations[0].Play;
Carlos
Re: How to execute the animation when chart is first drawn?
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |