我显示了带复选框的ExtraLegendTool,但复选框事件不起作用。 以下是显示ExtraLegend的代码:
procedure TFRChart.TCChartAfterDraw(Sender: TObject);
begin
if CKDisplay.Checked then
begin
with ExtraLegend do
begin
Active:= True;
Series := TBarSeries(Self.FindComponent('SeriesTotal'));
with Legend do
begin
LegendStyle := lsAuto;
CheckBoxes := True;
//MaxNumRows := 3;
CustomPosition := True;
Left:= TCChart.Legend.Left;
Top:= TCChart.Legend.ShapeBounds.Bottom + 10;
Width := TCChart.Legend.Width;
ShapeBounds.Right := TCChart.Legend.ShapeBounds.Bottom;
DrawLegend;
end;
end;
end;
end;
请查看下面的图片了解更多详情:
正如你在图片中看到的那样,我有两个类型为'Chart1.Legend.LegendStyle:= lsSeriesGroups'的图例,另一个是ExtraLegend。
当我取消选中Extralegend中的蓝色系列时,如何才能显示所有系列组的所有蓝条?
答案 0 :(得分:1)
您可以使用图表OnClick事件中的ExtraLegendTool Clicked()函数来获取已单击的图例的项目。然后,您可以激活/停用所需的任何系列 这个简单的例子对我来说似乎很合适:
procedure TForm1.Chart1Click(Sender: TObject);
var MousePos: TPoint;
index: Integer;
begin
MousePos:=Chart1.GetCursorPos;
index:=ChartTool1.Legend.Clicked(MousePos);
while (index>-1) and (index<Chart1.SeriesCount) do
begin
Chart1[index].Active:=not Chart1[index].Active;
index:=index+3;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
Chart1.SeriesGroups.Add;
Chart1.SeriesGroups.Add;
Chart1.SeriesGroups[0].Name:='This is Group 1';
Chart1.SeriesGroups[1].Name:='This is Group 2';
for i:=0 to 9 do
with Chart1.AddSeries(TBarSeries) as TBarSeries do
begin
FillSampleValues(5);
if (i<3) then
begin
Chart1.SeriesGroups[0].Add(Chart1[i]);
StackGroup:=0;
end
else
begin
Chart1.SeriesGroups[1].Add(Chart1[i]);
StackGroup:=1;
end;
MultiBar:=mbStacked;
end;
Chart1.Legend.LegendStyle := lsSeriesGroups;
Chart1.Draw;
with ChartTool1 do
begin
Active:= True;
//Series := TBarSeries(Self.FindComponent('SeriesTotal'));
Series := Chart1[0];
with Legend do
begin
LegendStyle := lsAuto;
CheckBoxes := True;
MaxNumRows := 3;
CustomPosition := True;
Left:= Chart1.Legend.Left;
Top:= Chart1.Legend.ShapeBounds.Bottom + 10;
Width := Chart1.Legend.Width;
ShapeBounds.Right := Chart1.Legend.ShapeBounds.Bottom;
DrawLegend;
end;
end;
end;