2015-06-18 219 views
0

我顯示了帶有複選框的ExtraLegendTool,但複選框事件不起作用。 這裏是顯示ExtraLegend代碼:TChart:在ExtraLegendTool中不工作的選中/未選中事件

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; 

請檢查如下因素圖像的更多詳細信息:

enter image description here

正如你可以在圖片中看到的,我有2個傳說類型之一'Chart1.Legend.LegendStyle:= lsSeriesGroups',另一個是ExtraLegend。

當我取消選中Extralegend中的藍色系列時,如何不顯示所有系列組的所有藍條?

回答

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; 
相關問題