Customizing legend values at runtime

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Errol
Newbie
Newbie
Posts: 1
Joined: Tue Aug 18, 2015 12:00 am

Customizing legend values at runtime

Post by Errol » Thu Aug 20, 2015 8:03 am

I am graphing data which is stored as SI values in database tables (e.g. pressure in pascals - Pa). The data is plotted in SI, with axes adjusted to show user values (e.g. pressure in bar or atmosphere). However, the legend displays the values in underlying SI units. What is the best way to modify the legend values at runtime (In your tutorials you have a link to "Customising Legend content at runtime" but it seems to be broken.)

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

Re: Customizing legend values at runtime

Post by Yeray » Fri Aug 21, 2015 10:48 am

Hello,
Errol wrote:I am graphing data which is stored as SI values in database tables (e.g. pressure in pascals - Pa). The data is plotted in SI, with axes adjusted to show user values (e.g. pressure in bar or atmosphere). However, the legend displays the values in underlying SI units. What is the best way to modify the legend values at runtime (In your tutorials you have a link to "Customising Legend content at runtime" but it seems to be broken.)
I'm not sure if OnGetLegendText event will fit your requirements or not, but note you can find an online version of the documentation here. Direct link to the section you mention here.

Wanting to show a set of values in two different units at the axes, marks or legend can be done by adding the values with the unit you want to show in the axis and with the other unit as Labels. Then you can set series' marks or legend to display values or labels. Ie:

Code: Select all

uses Series;

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
    v1, v2: double;
begin
  with Chart1.AddSeries(TBarSeries) as TBarSeries do
  begin
    for i:=0 to 5 do
    begin
      v1:=25+random*75; //value in units A
      v2:=v1*1000;      //transform from units A to units B
      Add(Round(v1), FormatFloat('#,##0.##', v2));
    end;

    Marks.Style:=smsLabel; //smsValue;
  end;

  Chart1.Legend.TextStyle:=ltsPlain; //ltsValue;
  Chart1.Axes.Bottom.LabelStyle:=talValue;
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