Modifying TAxisItem has no effect on the rendered chart

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
jens.mertelmeyer
Newbie
Newbie
Posts: 60
Joined: Fri Nov 22, 2013 12:00 am

Modifying TAxisItem has no effect on the rendered chart

Post by jens.mertelmeyer » Mon Feb 17, 2014 5:49 pm

Using the chart editor on the form designer, you can freely alter value and text of TAxisItems. See attached picture. That's pretty cool.

I am however unable to do this at runtime:

As an example, I'd like to shift every TAxisItem of the bottom axis by 0.5 to the right. Please see the following code snippet (in Delphi): It has no effect on the chart. However, All the TAxisItems already report my altered value. Is there something I'm doing wrong? I have a feeling I'm missing some kind of TChartAxis::Invalidate().

Code: Select all

procedure TMyForm.Button1Click(Sender: TObject);
const
	someOffset: Single = 0.5;
var
	axis: TChartAxis;
	axisItem: TAxisItem;
begin
	axis := Chart.Axes.Bottom;

	for axisItem in axis.Items do
		axisItem.Value := axisItem.Value + someOffset;

	// This even outputs the new and correct values
	for axisItem in axis.Items do
		self.Caption := self.Caption + ' ' + axisItem.Value.ToString();
		
end;
Attachments
By IDE.png
This shows how it works flawlessy during design time
By IDE.png (60.03 KiB) Viewed 7894 times

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Modifying TAxisItem has no effect on the rendered chart

Post by Narcís » Wed Feb 19, 2014 2:44 pm

Hi Jens,

What you need to do is set Axis.Items to manual. If, they are automatic, their values won't be used. If you have a look at the editor screen-shot you posted, to be able to set Axis.Items values manually, you need to uncheck the "Automatic" checkbox. At run-time you can do this:

Code: Select all

  TheAxis:=Chart1.Axes.Bottom;
  TheAxis.Items.Automatic:=False;

  for i:=0 to TheAxis.Items.Count - 1 do
  begin
    TheAxis.Items[i].Value:=TheAxis.Items[i].Value + 0.5;
    //TheAxis.Items[i].Text:=FloatToStr(TheAxis.Items[i].Value + 0.5);
  end;
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

jens.mertelmeyer
Newbie
Newbie
Posts: 60
Joined: Fri Nov 22, 2013 12:00 am

Re: Modifying TAxisItem has no effect on the rendered chart

Post by jens.mertelmeyer » Wed Feb 19, 2014 2:52 pm

Thank you!

It should however be noted that Setting an axis to Manual removes all the (previously generated) automatic Axis items and I will have to create and add them myself. However, that works like a charm.

Thanks a ton!

Best regards.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Modifying TAxisItem has no effect on the rendered chart

Post by Narcís » Wed Feb 19, 2014 3:15 pm

Hi Jens,

Calling Items.Clear does the job:

Code: Select all

  Chart1.Axes.Bottom.Items.Clear;
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply