Page 1 of 1

Change dynamically the Bottom Axis Title

Posted: Tue Jan 22, 2013 3:12 pm
by 16564598
Hello,
I have an application in which I want to dynamically change the bottom axis title caption of a TChart.
In fact in the chart I have some TLineSeries representing time course of a variable, so the bottom axis is the time scale.
I want to show the current time value (depending from the application status) in the bottom axis title caption.
To do this, I simply added some code in the Chart.OnAfterDraw event handler to set the new value of Chart.BottomAxis.Title.Caption.
But the title caption text that I set is not displayed, I need to force another TChart refresh to display it and this slows down the application.
Could you please help me?
I'm using VCL2011 for RAD Studio XE.

Thank you very much.
Piero

Re: Change dynamically the Bottom Axis Title

Posted: Wed Jan 23, 2013 9:59 am
by 10050769
Hello Piero,

I can not reproduce your problem using next code in last version of TeeChartVCL2012:

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
begin
Series1.FillSampleValues(10);
end;

procedure TForm1.Chart1AfterDraw(Sender: TObject);
begin
Chart1.Axes.Left.Title.Caption:= 'Title:'+ IntToStr(Index1);
Index1:= Index1+1;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
Chart1.View3D:= False;
Series1.FillSampleValues(10);
Chart1.Axes.Left.Title.Visible:=True;
Index1:=0;
Chart1.Draw;
end;
Check if my previous code works in your your version of TeeChartVCL, if it work please try to use it to solver your problem in your application.
On the other hand, would be very grateful, if you can check your project using the TeeChartVCL 2012 Evaluation version, and tell us if your problem appears using last version of TeeChartFor.Net. If your problem persist using last version, please try to arrange a simple code because we can reproduce your problem here and try to find a solution for you.


Thanks,

Re: Change dynamically the Bottom Axis Title

Posted: Wed Jan 23, 2013 11:47 am
by 16564598
Hello Sandra,
your code works in my TeeChart VCL. By comparing it with my application, I discovered that the problem occurs when there are two forms,
that is one form containing the TChart, and the second form that indirectly sets the TChart title caption.
I attach a simple two forms project made with Delphi XE to this post so you can try to reproduce the problem, or tell me if there is something I'm doing wrong.
Thank you very much for your support.
Regards,
Piero

Re: Change dynamically the Bottom Axis Title

Posted: Thu Jan 24, 2013 11:19 am
by narcis
Hi Piero,

Thanks for the example project. What about updating the bottom axis title at the ChangeValueIndex method so you don't need to repaint the chart to update it? Here's the code modified:

Code: Select all

procedure TForm14.ChangeIndexValue(NewVal: integer);
begin
   IndexValue:=NewVal;
   Label1.Caption:='Index1: '+IntToStr(IndexValue);
   //Chart1.Refresh;
   Chart1.Axes.Bottom.Title.Caption:= XAxisTitle+ IntToStr(IndexValue);
end;

procedure TForm14.Chart1AfterDraw(Sender: TObject);
begin
   //Chart1.Axes.Bottom.Title.Caption:= XAxisTitle+ IntToStr(IndexValue);
end;

Re: Change dynamically the Bottom Axis Title

Posted: Thu Jan 24, 2013 1:12 pm
by 16564598
Hello Narcis,
you're right, in this way it works. I put the code in th OnChartAfterDraw event just because in that event handler there is some other code, but I can also use an external procedure as you suggested.
So thank you very much for your support!
Best Regards,
Piero