OnGetLegendText - Format Values using ValueFormat property

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
keitht
Newbie
Newbie
Posts: 2
Joined: Thu Nov 30, 2006 12:00 am

OnGetLegendText - Format Values using ValueFormat property

Post by keitht » Wed Aug 27, 2008 9:03 pm

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;

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 Aug 28, 2008 9:02 am

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.
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

keitht
Newbie
Newbie
Posts: 2
Joined: Thu Nov 30, 2006 12:00 am

Post by keitht » Thu Aug 28, 2008 7:24 pm

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

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

Post by Narcís » Tue Sep 02, 2008 8:32 am

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.
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