I recently came across the series group feature which allows you to show or hide different groups of your chart series in the chart legend.
I see that when using the series group, if you choose to show the group names in the legend, that is all you get, the name of the group. Is there a way to show a symbol next to the group name? I ask because it would make it a lot easier to do the following.
Suppose I have 4 box series in a chart, Series1, Series2, Series3, Series4. Series1 and Series3 are red and Series2 and Series4 are blue. Under ordinary circumstances, if I make the legend visible, I will see all four series listed in the legend with two of the symbols being identical, and red, while the other two are identical and blue. But let us say instead I want my legend to only show two items, to have a red symbol with the word "odd" and a blue symbol with the word "even." Well, by using series groups, I could put Series1 and Series3 in a group and name it "Odd" and could put Series2 and Series4 in a group and call it "Even," but that will not give me the red and blue symbols that I would like to see in the legend.
Right now I end up hiding series3 and series4 from the legend and renaming Series1 to "Odd" and Series2 to "Even." But this can get unwieldy when you have 20 or 30 series and more then two groupings of colors. So I was wondering if there is an easy way to do this with groups.
Thanks!
SDE
Series Group
Re: Series Group
Hello,
Here it is a simple example of drawing a symbol manually on the legend:
Here it is a simple example of drawing a symbol manually on the legend:
Code: Select all
procedure TForm1.Chart1AfterDraw(Sender: TObject);
var i, xPos, yPos: Integer;
begin
xPos:=Chart1.Legend.Left + Chart1.Legend.Width - 15;
for i:=0 to Chart1.SeriesGroups.Count-1 do
begin
yPos:=Chart1.Legend.Item[i].Top+2;
with Chart1.Canvas do
begin
Brush.Color:=Chart1.SeriesGroups[i].Series[0].Color;
Rectangle(Rect(xPos, yPos, xPos+10, yPos+10), 0);
end;
end;
end;
procedure TForm1.Chart1GetLegendRect(Sender: TCustomChart; var Rect: TRect);
begin
Rect.Right:=rect.Right+15;
end;
procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
(Chart1.SeriesGroups.Add as TSeriesGroup).Name:='Red';
(Chart1.SeriesGroups.Add as TSeriesGroup).Name:='Blue';
for i:=0 to 10 do
begin
Chart1.AddSeries(TLineSeries).FillSampleValues();
if (i mod 2 = 0) then
Chart1[i].Color:=clRed
else
Chart1[i].Color:=clBlue;
Chart1.SeriesGroups.Items[i mod 2].Add(Chart1[i]);
end;
Chart1.Legend.LegendStyle:=lsSeriesGroups;
Chart1.Legend.CheckBoxes:=true;
end;
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |