Recent

Author Topic: TAchart, lineseries: different pen width for line and legend  (Read 3124 times)

jur

  • New member
  • *
  • Posts: 7
TAchart, lineseries: different pen width for line and legend
« on: January 25, 2019, 04:17:07 pm »
Hi,

For highest speed I want to draw multiple lineseries with pen.width=1, (win10, > 1e6 datapoints)
but for visibility I want to draw the legend symbols with pen.width=3.

I tried re-assigning the event as below: this works, the linewidth is changed,  but for all series the same color is used, since the parameter  AIndex = 0 for all draw operations. How can I know which line/legend is currently drawn, so I can change the pen.color?

Regards, any help is welcome

Jur

============
 TLineseries(form1.chart1.Series[lijnnr]).Legend.OnDraw := @FuncSeries1ChartSeriesLegendDraw ; 

procedure TForm1.FuncSeries1ChartSeriesLegendDraw(ACanvas: TCanvas;
  const ARect: TRect; AIndex: Integer; AItem: TLegendItem);
begin
  Unused(AIndex, AItem);
  ACanvas.Pen.Width:= 3;
  y0 := (ARect.Top + ARect.Bottom) div 2;
  ACanvas.MoveTo(ARect.Left, y0);
  w := ARect.Right - ARect.Left;
  for x := 0 to w do
    ACanvas.LineTo(
      ARect.Left + x, y0);
end;
==================

wp

  • Hero Member
  • *****
  • Posts: 11830
Re: TAchart, lineseries: different pen width for line and legend
« Reply #1 on: January 25, 2019, 05:06:05 pm »
The TLegendItem which is passed to the Legend.OnDraw event has a property "Owner", and this points to the series to which the item belongs. Then you can get the pen from the "LinePen" property of the series and replace the width:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Chart1LineSeries1ChartSeriesLegendDraw(ACanvas: TCanvas;
  2.   const ARect: TRect; AIndex: Integer; AItem: TLegendItem);
  3. begin
  4.   if AItem.Owner is TLineSeries then begin
  5.     ACanvas.Pen := TLineSeries(AItem.Owner).LinePen;
  6.     ACanvas.Pen.Width := 3;
  7.     ACanvas.Line(ARect.Left, (ARect.Top + ARect.Bottom) div 2, ARect.Right, (ARect.Top+ARect.bottom) div 2);
  8.   end;
  9. end;

jur

  • New member
  • *
  • Posts: 7
Re: TAchart, lineseries: different pen width for line and legend
« Reply #2 on: January 25, 2019, 06:13:53 pm »
Thanks wp,

works great!

Regards, Jur

 

TinyPortal © 2005-2018