@ask:
Could you please add a the following public method to TBasicChartSeries? This method, DrawSeriesIcon, would enable population of an TImageList with the icon of each series. The imagelist could be used in further controls for series selection (Listbox, Listview etc.).
This is my proposed code:
procedure TBasicChartSeries.DrawSeriesIcon(ADrawer:IChartDrawer; const ARect:TRect);
var
legItems : TChartLegendItems;
i : integer;
begin
legItems := TChartLegendItems.Create;
try
GetLegendItemsBasic(legItems);
for i:=0 to legItems.Count-1 do
(legItems[i] as TLegendItem).Draw(ADrawer, ARect);
finally
legItems.Free;
end;
end;
For those interested, this would be the code to populate the imagelist with the series icons:
procedure PopulateSeriesImageList(AChart: TChart; AImageList:TImageList);
var
drawer: IChartDrawer;
bmp : TBitmap;
R : TRect;
i : integer;
begin
AImageList.Clear;
bmp := TBitmap.Create;
try
bmp.Width := AImageList.Width;
bmp.Height := AImageList.Height;
R := Rect(0, 0, bmp.Width, bmp.Height);
bmp.Canvas.Brush.Color := clWindow;
drawer := TCanvasDrawer.Create(bmp.Canvas);
for i:=0 to AChart.SeriesCount-1 do
begin
bmp.Canvas.FillRect(R);
AChart.Series[i].DrawSeriesIcon(drawer, R);
AImageList.Add(bmp, nil);
end;
finally
bmp.Free;
end;
end;