Problem with Axislabel

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
FHG_AST
Newbie
Newbie
Posts: 9
Joined: Wed Mar 05, 2008 12:00 am

Problem with Axislabel

Post by FHG_AST » Tue Jul 20, 2010 9:03 am

Hi@All

I have build a unit conversion componenten that changes the labels of the chartaxis so that I can switch from meters to millimeters or feet.
I do this unit conversion in the GetAxisLabel function like this

Code: Select all

Procedure TUnitconv.GetAxisLabel(Sender: TChartAxis; Series: TChartseries; ValueIndex: Integer; var LabelText: string);
var FUCF:double;
    DS:Toracledataset;
    SN:TChartAxis;
    Tag:integer;
begin
inherited;
    SN:=Sender;
    try
    if assigned(Series) then
    begin
     DS:=Toracledataset(Series.DataSource);

     //Hier irgendwie herausbekommen ob es die vertikale oder die horizontale achse ist
     if (Series.GetVertAxis =SN) then
     begin
      if DS.FieldByName(Series.YValues.ValueSource).Tag>0 then
      begin
      //get the unit conversion factor
      FUCF:=Funits[Funititems[Toracledataset(Series.datasource).FieldByName(Series.YValues.ValueSource).Tag,2]].CFaktor;
      Labeltext := Floattostr(strtofloat(Labeltext)/FUCF); //calculate the new label
      end;
     end;

     if (Series.GetHorizAxis =SN) then
     begin
      if DS.FieldByName(Series.xValues.ValueSource).Tag>0 then
      begin
      //get the unit conversion factor
      FUCF:=Funits[Funititems[Toracledataset(Series.datasource).FieldByName(Series.XValues.ValueSource).Tag,2]].CFaktor;
      Labeltext := Floattostr(strtofloat(Labeltext)/FUCF);//calculate the new label
      end;
     end;
    end;
    Except
    end;
end;
My problem is that this only works if
TChartseries(parent.Components[j]).ParentChart[sindex].GetVertAxis.LabelStyle:=talText;

Then the unit conversion works well but the ditance between the axis labels is not equal.
Image

If I switch to
TChartseries(parent.Components[j]).ParentChart[sindex].GetVertAxis.LabelStyle:=talValue;
then the distance of the labels is equal bit then the unit isn't converted.
Image

Is there a way to get the unit conversion with equal label distances run?

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Problem with Axislabel

Post by Yeray » Tue Jul 20, 2010 3:04 pm

Hi FHG_AST,

With talText, an axis label will be drawn for each point in the series (in fact, in the first series linked to that axis) that has label. So this LabelStyle isn't thought to prevent labels overlap or to be drawn in equal distances.

However, you could use custom labels like in the demo at All features/Welcome !/Axes/Labels/Custom Labels. You can clear all the labels from the left axis and add the labels you wish.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

FHG_AST
Newbie
Newbie
Posts: 9
Joined: Wed Mar 05, 2008 12:00 am

Re: Problem with Axislabel

Post by FHG_AST » Wed Jul 21, 2010 6:42 am

Is there another posibility to change the labels on the left axis between the value is read from the dataset and the display on the screen wwith the use of talValue?

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Problem with Axislabel

Post by Yeray » Wed Jul 21, 2010 11:01 am

Hi FHG_AST,

Yes, you can use OnGetAxisLabel event to change the labels. For example:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
    tmp: Double;
begin
  Chart1.View3D:=false;
  Chart1.MarginLeft:=15;

  tmp:=Random(1000);
  Series1.Add(tmp, FloatToStr(tmp));
  for i:=1 to 99 do
  begin
    tmp:=Series1.YValue[i-1] + Random(10) - 5;
    Series1.Add(tmp, FloatToStr(tmp));
  end;

  Chart1.Axes.Left.LabelStyle:=talValue;
end;

procedure TForm1.Chart1GetAxisLabel(Sender: TChartAxis; Series: TChartSeries;
  ValueIndex: Integer; var LabelText: string);
begin
  if (Sender = Chart1.Axes.Left) then
  begin
    LabelText:=LabelText + ' -> ' + FormatFloat('#,##0.###',StrToFloat(LabelText)*1000)
  end;
end;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply