Page 1 of 1

OnGetLegendText - Format Values using ValueFormat property

Posted: Wed Aug 27, 2008 9:03 pm
by 9243228
How can I format series values in the OnGetLegendText event using the ValueFormat mask. I have tried using Delphi's FormatMaskText function, but it doesn't format the string correctly.

The ValueFormat property for the series is always set to either '#,##0' or '#,##0.00'. If I don't use GetLegendText, the values are formatted correctly, so I know the ValueFormat mask is set correctly.

Below is a simple example of what I am trying to do.

Code: Select all

procedure TForm.DBChart1GetLegendText(Sender: TCustomAxisPanel;
  LegendStyle: TLegendStyle; Index: Integer; var LegendText: String);
var
  vValueMask : String;
begin

  if LegendStyle = lsValues then
  begin

    vValueMask := FChart.SeriesList[0].ValueFormat;

    LegendText := FormatMaskText(vValueMask, FloatToStr(FChart.SeriesList[0].YValue[Index])) + #6
      + FChart.SeriesList[0].Labels[Index];

  end; {if}

end;

Posted: Thu Aug 28, 2008 9:02 am
by narcis
Hi keitht,

Code below seems to work fine for me here. Which is the exact problem you are having with it?

Code: Select all

uses MaskUtils;

procedure TForm1.Chart1GetLegendText(Sender: TCustomAxisPanel;
  LegendStyle: TLegendStyle; Index: Integer; var LegendText: String);
var
  vValueMask, tmp : String;
begin

  if LegendStyle = lsValues then
  begin

    vValueMask := Chart1[0].ValueFormat;
    tmp:=FormatMaskText(vValueMask, FloatToStr(Chart1[0].YValue[Index]));
    tmp:=tmp + #6 + Chart1[0].Labels[Index];

    LegendText := tmp;

  end; {if}
end;

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
  Series1.Clear;

  for i:=0 to 25 do
    Series1.Add(random,'point ' + IntToStr(i));
end;
Thanks in advance.

Posted: Thu Aug 28, 2008 7:24 pm
by 9243228
Thanks, NarcĂ­s, for your quick reply. I'm not sure what the difference is. When I create a new application project in Delphi, add a TChart, copy and paste your code into the project, my legend values do not come out formatted correctly. I'm getting this in the legend...

Code: Select all

0,   .     point 0
0,   .     point 1
0,   .     point 3
0,   .     point 4
As you can see the thousands separator and decimal are being included
unnecessarily. This is what I get when I use all default settings with a newly created TChart, so I can't understand what I'm doing wrong. The Series ValueFormat property is set to the default: #,##0.###

Any idea why this might be happening. I am using TeeChart Pro v. 7.07 with Delphi 7.

Thanks,
Keith T

Posted: Tue Sep 02, 2008 8:32 am
by narcis
Hi Keith,

We have checked that this works fine for us here using v7.12 (only available for BDS 2006, RAD Studio 2007 and sourcecode version) and v8. According to our records your company also holds v8 licenses. Could you please try if this works fine at your end using v8?

Thanks in advance.