Keeping the Legend Symbols the same size

TeeGrid VCL / FMX for Embarcadero RAD Studio, Delphi, C++ Builder and Lazarus Free Pascal.
Post Reply
EdDressel
Newbie
Newbie
Posts: 35
Joined: Mon Nov 25, 2019 12:00 am

Keeping the Legend Symbols the same size

Post by EdDressel » Thu Mar 12, 2020 8:46 pm

In the attached demo, you can select if the line for the pie series is visible or not, and if it is, if it is white or black.

THis part works fine.

I would like to keep the symbols in the legend large--without the border around them (like the chart when no series pen is visible).

Can this be done?

Thank you,

Ed Dressel
Attachments
Donut and Legend.zip
(6.88 KiB) Downloaded 2006 times
Ed Dressel
President
RetireReady Solutions

EdDressel
Newbie
Newbie
Posts: 35
Joined: Mon Nov 25, 2019 12:00 am

Re: Keeping the Legend Symbols the same size

Post by EdDressel » Fri Mar 13, 2020 10:15 pm

I tried the following code but it colors each symbol with the same color (of course). I don't know how to get the color for each slice.

Code: Select all

  Chart1.Legend.Symbol.OnDraw := ChartLegendDraw;


procedure TForm1.ChartLegendDraw(Sender: TObject; aSeries:TChartSeries; ValueIndex:Integer; R:TRect);
var
  lBarSeries: TBarSeries;
  lCanvas: TCanvas3D;
  lBlend: TTeeBlend;
begin
  lCanvas := aSeries.ParentChart.Canvas;
  lCanvas.Brush.Color := aSeries.Color;
  lCanvas.Pen.Color := lCanvas.Brush.Color;
  lCanvas.Rectangle(R);
end;
Thank you for your help.

Ed Dressel
Ed Dressel
President
RetireReady Solutions

EdDressel
Newbie
Newbie
Posts: 35
Joined: Mon Nov 25, 2019 12:00 am

Re: Keeping the Legend Symbols the same size

Post by EdDressel » Tue Mar 17, 2020 6:01 pm

I posted this in the wrong group, but in case you are wondering, here is the solution:

procedure TForm1.ChartLegendDraw(Sender: TObject; aSeries:TChartSeries; aValueIndex:Integer; aR:TRect);
var
lCanvas: TCanvas3D;
lClr: TColor;
begin
lCanvas := aSeries.ParentChart.Canvas;
lClr := aSeries.LegendItemColor(aValueIndex);
lCanvas.Brush.Color := lClr;
lCanvas.Pen.Color := lClr;
lCanvas.Rectangle(aR);
end;


This concerns me about FMX though--no one here.
Ed Dressel
President
RetireReady Solutions

Marc
Site Admin
Site Admin
Posts: 1271
Joined: Thu Oct 16, 2003 4:00 am
Location: Girona
Contact:

Re: Keeping the Legend Symbols the same size

Post by Marc » Wed Mar 18, 2020 12:19 pm

Hello Ed,

Code: Select all

This concerns me about FMX though--no one here.
Yes, we were slow to react to your post. Workload doesn't always allow us to get to every post straight away; we should have noticed your post on the TeeGrid forum and moved it to TeeChart.

Regards,
Marc
Steema Support

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Keeping the Legend Symbols the same size

Post by Yeray » Wed Mar 18, 2020 3:38 pm

Hello,

An alternative would be to hide the pie series from the legend and use a point series for each item you want to be in the legend. Ie:

Code: Select all

var i: Integer;
begin
  for i:=0 to Series1.Count-1 do
    with TPointSeries(Chart1.AddSeries(TPointSeries)) do
    begin
      Pointer.Pen.Visible:=False;
      Pointer.Size:=6;
      Title:=Series1.LegendString(i,Chart1.Legend.TextStyle);
      Color:=Series1.ValueColor[i];
    end;

  Series1.ShowInLegend:=False;
  Chart1.Walls.Hide;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply