For a PieChart, TChart provides the ability to show a label for each pie slice showing the value, the percent, the percent + total, etc. I have been asked to customize the labels for the slices, introducing two new options.
Specifically, I have been asked to allow a label in the format of LABEL VALUE PERCENT TOTAL. Currently, I can provide all of the desired info in a single label with the exception of the Value. Is there a not-too-difficult way to implement this? Any samples you can point me to, or sample code snippets would be greatly appreciated.
The second item I have been asked to do is allow users to define a mask for displaying data. Many times, the data in our charts is measured in millions or billions of units. What our users would like to have is the ability to tell TChart to show a value like 1,234,567 as 1.2M for 1.2 million. Similarly, they want to use K for thousands, so our example becomes 1,235K.
Of course, users being users, they aren't satisfied with a simple request. They also want to be able to specify a number of decimal places, rounding as appropriate. So the 1,234,567 could correctly be displayed as 1.23M, 1.235M, 1,234,567.000, or 1,234.6K. We convinced the users that any mask applied would have to be applied to all slices; that is, a single pie of 3 slices would not have one slice unmasked, one masked for thousands, and another masked for millions.
The important thing for the users, though, is the masked value MUST work with the various label styles TChart currently allows.
Is such a thing possible?
Thanks.
Rich
Customizing PieSlice labels
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi Rich,
Yes, this is possible, you can customize the series marks in the OnGetMarkText event. On that event you can also "mask" the series values to be displayed in the marks. Here you have an example:
Yes, this is possible, you can customize the series marks in the OnGetMarkText event. On that event you can also "mask" the series values to be displayed in the marks. Here you have an example:
Code: Select all
procedure TForm8.FormCreate(Sender: TObject);
var i: Integer;
begin
Randomize;
for i := 0 to 10 do
Series1.AddPie(random*10000, 'Point ' + IntToStr(i), clTeeColor);
Series1.Marks.Style:=smsPercentTotal;
end;
function TForm8.MaskValue(Val: Double; Format: String): String;
begin
if Format='0.0K' then
result:=FloatToStrF(Val/1000, ffGeneral, 1, 1) + 'K'
else
result:=FloatToStr(Val);
end;
procedure TForm8.Series1GetMarkText(Sender: TChartSeries; ValueIndex: Integer;
var MarkText: string);
begin
MarkText:=Sender.Labels[ValueIndex] + ', ' +
MaskValue(Sender.YValue[ValueIndex],'0.0K') + ', ' +
MarkText;
end;
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |