Page 1 of 1

How to get the text of a Legend item

Posted: Thu Mar 09, 2017 7:06 pm
by 16880166
I searched but couldn't find this anywhere. Right now, I have created drill-down charts when a user clicks on a slice in a pie chart by adjusting the SQL. Getting the text was easy.

Code: Select all

Series.Labels[ValueIndex]
But OnClickLegend does not return a ValueIndex. I want to drill-down the same way in the legend as I do now in the Chart. How can I get the text of a legend item when clicked?

Re: How to get the text of a Legend item

Posted: Fri Mar 10, 2017 10:05 am
by yeray
Hello,

This works fine for me:

Code: Select all

procedure TForm1.Chart1ClickLegend(Sender: TCustomChart; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  Caption:=Chart1.Legend.Item[Chart1.Legend.Clicked(X, Y)].Text;
end;