Page 1 of 1

Legend, show Series Name and Series Total Value

Posted: Wed Mar 15, 2017 7:21 pm
by 16880166
I have attached my chart. How can I change the legend to show the Series Name along with the Total value of the Series?

Re: Legend, show Series Name and Series Total Value

Posted: Thu Mar 16, 2017 1:17 pm
by yeray
Hello,

You could use OnGetLegendText event. Ie:

Code: Select all

procedure TForm1.Chart1GetLegendText(Sender: TCustomAxisPanel;
  LegendStyle: TLegendStyle; Index: Integer; var LegendText: string);
var i: Integer;
begin
  if Index<Chart1.SeriesCount then
    LegendText:=LegendText + ' $' + FormatFloat('#,##0.##', Chart1[Index].YValues.Total);
end;

Re: Legend, show Series Name and Series Total Value

Posted: Thu Mar 16, 2017 2:28 pm
by 16880166
Thank you. I'll give it a shot.

Re: Legend, show Series Name and Series Total Value

Posted: Thu Jul 13, 2017 5:36 pm
by 16880166
I have another question along this same lines. I have a pie chart of categories (Attached). If transactions don't have any assigned category, the legend just displays the amount. I would like to add the text 'No Categories' in front of the amount but I can't seem to format it the way it is in the legend (Text left justified and amount right justified).

Thanks.

Re: Legend, show Series Name and Series Total Value

Posted: Fri Jul 14, 2017 7:18 am
by yeray
Hello,
realsol wrote:I have another question along this same lines. I have a pie chart of categories (Attached). If transactions don't have any assigned category, the legend just displays the amount. I would like to add the text 'No Categories' in front of the amount but I can't seem to format it the way it is in the legend (Text left justified and amount right justified).
I'm not sure to understand why don't you add the uncategorized value as you do with the others, with the "No Categories" label. Ie:

Code: Select all

  Series1.Add(316560, 'No Categories');
In case you are adding the values connecting the series to a dataset, you can loop your values and set the label at those points with empty labels. Ie:

Code: Select all

  for i:=0 to Series1.Count-1 do
    if Series1.Labels[i] = '' then
      Series1.Labels[i]:='No Categories';

Re: Legend, show Series Name and Series Total Value

Posted: Fri Jul 14, 2017 6:00 pm
by 16880166
Thanks. I ended up using the OnGetLegendText for the Chart and added

Code: Select all

if Series1.Labels[Index] = '' then
      Series1.Labels[index]:='No Categories';
Worked perfectly. Thanks.