Page 1 of 1
Customizing legend values at runtime
Posted: Thu Aug 20, 2015 8:03 am
by 16575203
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.)
Re: Customizing legend values at runtime
Posted: Fri Aug 21, 2015 10:48 am
by yeray
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;