Page 1 of 1

Problem with Axislabel

Posted: Tue Jul 20, 2010 9:03 am
by 10548492
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?

Re: Problem with Axislabel

Posted: Tue Jul 20, 2010 3:04 pm
by yeray
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.

Re: Problem with Axislabel

Posted: Wed Jul 21, 2010 6:42 am
by 10548492
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?

Re: Problem with Axislabel

Posted: Wed Jul 21, 2010 11:01 am
by yeray
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;