Centering the Left Axis on a certain position in bar series

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Aviel_Consist
Newbie
Newbie
Posts: 3
Joined: Thu Jan 31, 2008 12:00 am

Centering the Left Axis on a certain position in bar series

Post by Aviel_Consist » Wed Mar 12, 2008 9:49 am

hi,
i have a BarSeries that needs its Left axis 0 position to allways be the center of the chart.

here's an example :

Image

what i have here are two bars with positive values,
below them is enough space for similer bar's with same but negative values.

to do this i have to force the Maximum and Minimum properties of the left axis.
the problem here is that without "Auto" property i cant know whats the REAL maximum because of the label margins and styles etc..

so what i need is basically a way to calculate or retreive the real maximum and minimum values taking in account all mark padding and size etc.

the current example was made by settin auto then setting it to manual and adjusting visually until it looks like auto mode..

this is kind of hard to explain but i hope you understood what im looking for.

thank you.[/img]

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

Post by Narcís » Wed Mar 12, 2008 9:59 am

Hi Aviel_Consist,

If I understood correctly what you are trying to achieve you could do something like in the example here. This a TeeChart Pro ActiveX with VB6 example but you shouldn't have much problems porting it to the VCL version. In case of any problem don't hesitate to let us know.
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

Aviel_Consist
Newbie
Newbie
Posts: 3
Joined: Thu Jan 31, 2008 12:00 am

Post by Aviel_Consist » Wed Mar 12, 2008 12:30 pm

Hi, i have tried the example you linked to, this is not exactly what i needed.. unless i did not port it right .. what this does is move the axis itself.

what i need is to make sure the maximum and minimum are both negatives of each other even in automatic mode..

so say if i have 2 bars with values 100, and 90.
the maximum for the left axis would be 100, and i would see the 0 mark at the bottom of the chart.
what i want is to have the minimum be the negative of the maximum that way the 0 mark would be on the center of the chart.

obviously i could just do Minimum := -Maximum BUT.. the maximum is calculated automatically by the Auto property which sets it a bit higher than the maximum bar value to show the label marks etc..
and i cant access this value.. or atleast i havent found how.


so either a way to do this.. or some sort of way to get the maximum TChart has set after the Auto property.

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

Post by Narcís » Thu Mar 13, 2008 9:40 am

Hi Aviel_Consist,

You can try doing something as in the code below. You can choose wheter using MarksOffset or not.

Code: Select all

procedure TForm1.Chart1AfterDraw(Sender: TObject);
var MarksOffset : integer;
begin
  MarksOffset := Series1.Marks.Callout.Length;
  Chart1.Axes.Left.SetMinMax(chart1.Axes.Left.Maximum + MarksOffset , -Series1.YValues.MaxValue);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Series1.FillSampleValues();
  Chart1.Draw;
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

Aviel_Consist
Newbie
Newbie
Posts: 3
Joined: Thu Jan 31, 2008 12:00 am

Post by Aviel_Consist » Fri Mar 14, 2008 7:02 am

hello, thank you for your reply it is much appreciated.

but there is still one little issue.. it seems to not take account the mark box height and offset since they travel off-chart.. like this :


Image

any solution to this?

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

Post by Narcís » Mon Mar 17, 2008 12:34 pm

Hi Aviel_Consist,

Ok, you can do something like this:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.Draw;
end;

procedure TForm1.Chart1AfterDraw(Sender: TObject);
begin
  Chart1.Axes.Left.SetMinMax(Series1.YValues.MaxValue , -Series1.YValues.MaxValue);
  Chart1.Axes.Left.MaximumOffset := Series1.Marks.ArrowLength + Series1.Marks.Shadow.Size+ round(Series1.Marks.Font.Size) + Series1.Marks.Margins.Bottom
end;
You could also calculate font height using textheight property.
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