Add Offset to Axis

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
moelski
Newbie
Newbie
Posts: 92
Joined: Tue Jun 19, 2007 12:00 am
Contact:

Add Offset to Axis

Post by moelski » Wed Sep 10, 2008 8:22 am

Hi !

We use TChart to display measurement data. And often we (and of course our customers) have a situation like this:
Image

As you can see the two charts are at the top of the chart. So we need any solution to have an offset for the max axis value. Something like Maximumvalue + 10%. I know that there is an Offset property for each axis but this is calculated in pixel. This is not a really good solution.

The best way would be a rounding to the next integer value. For example if you have a maximum value of 12,56 the axis should have an end value of 13.

Can you give me a hint (or if possible some code) how we can achieve this?

Greetz
Dominik

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 Sep 10, 2008 8:56 am

Hi Dominik,

You already know min. and max. left axis values. Using Chart1.Axes.Left.CalcYPosValue method you can calculate the number of pixels used for a certain scale. Also, you can get axis size using Chart1.Axes.Left.IAxisSize. Knowing that you can calculate the number of pixels for setting MinimumOffset and MaximumOffset as you request.

Hope this helps!
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

moelski
Newbie
Newbie
Posts: 92
Joined: Tue Jun 19, 2007 12:00 am
Contact:

Post by moelski » Wed Sep 10, 2008 9:04 am

Hi Narcis,

and where should I place this code?
Which event would be the best for this?

Greetz Dominik

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 Sep 10, 2008 9:08 am

Hi Dominik,

You should place this in the OnAfterDraw event or call Chart1.Draw before because axes need to be plotted so that necessary properties have valid values.
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

moelski
Newbie
Newbie
Posts: 92
Joined: Tue Jun 19, 2007 12:00 am
Contact:

Post by moelski » Wed Sep 10, 2008 11:38 am

Hi Narcis,

I wrote a small demo but it works not the way I want it to do :roll:

Take a look at my project:
http://www.logview.info/Downloads/TopLine.zip

Use the radio button at the left side to get a new chart.draw. In Chart1AfterDraw is the calculation for the Offset.

But as you will see it will set to late. You start with MaximumOffset := 0. Then click on "Set to 900 max" which will add an offset. But nothing will happen. Click back to "do nothing" and you will get the offset.

Must I Call Chart.Draw in the Chart1AfterDraw Event? :shock:
This would draw the chart always twice compared to normal drawing.

Hope you can help me.

Greetz Dominik

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 Sep 10, 2008 1:33 pm

Hi Dominik,

Never use Draw method in OnAfterDraw event as you'd fall into an endless loop :!:.

Series2 is associated to Right axis. That's probably why you didn't notice the offset. Not using OnAfterDraw method and implementing SpacerClick as shown below works fine for me here.

Code: Select all

procedure TForm1.SpacerClick(Sender: TObject);
var Value, Diff : Double;
begin
  With Memo1.Lines, Chart1.Axes.Left do
  begin
    Clear;

    if Option_Aufrunden.Checked then begin
      Add('---------------------------------------');
      Add('Minimum Pixels  : ' + IntToStr(CalcYPosValue(Minimum)));
      Add('Minimum Value   : ' + FloatToStr(Minimum));
      Add('Maximum Pixels  : ' + IntToStr(CalcYPosValue(Maximum)));
      Add('Maximum Value   : ' + FloatToStr(Maximum));
      Add('IAxisSize       : ' + IntToStr(IAxisSize));

      Value := (Maximum - Minimum) / IAxisSize;
      Add('Float pro Pixel : ' + FloatToStr(Value));

      Diff  := 900 - Maximum;
      Add('Differenz       : ' + FloatToStr(Diff));
      Add('Pixels Offset   : ' + FloatToStr(Diff / Value));

      MaximumOffset := Trunc(Diff / Value);
    end
    else
      MaximumOffset := 0;

    Chart1.Axes.Right.MaximumOffset:=MaximumOffset;
    Add('MaximumOffset   : ' + IntToStr(MaximumOffset));
  end;
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

Post Reply