Page 1 of 1

Keeping the Legend Symbols the same size

Posted: Thu Mar 12, 2020 8:46 pm
by 16587426
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

Re: Keeping the Legend Symbols the same size

Posted: Fri Mar 13, 2020 10:15 pm
by 16587426
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

Re: Keeping the Legend Symbols the same size

Posted: Tue Mar 17, 2020 6:01 pm
by 16587426
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.

Re: Keeping the Legend Symbols the same size

Posted: Wed Mar 18, 2020 12:19 pm
by Marc
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

Re: Keeping the Legend Symbols the same size

Posted: Wed Mar 18, 2020 3:38 pm
by yeray
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;