Recent

Author Topic: TAChartListBox Autoextend possible? [SOLVED]  (Read 1430 times)

AL

  • Sr. Member
  • ****
  • Posts: 261
TAChartListBox Autoextend possible? [SOLVED]
« on: November 20, 2019, 04:59:43 pm »
Is there a way to make the tchartlistbox autoextend to show a new long serie name?

Thanks   
AL
« Last Edit: January 08, 2020, 10:37:02 pm by AL »
Laz 3.1, fpc 3.2.2, Win10
Laz 3.1  fpc 3.2.2, MacOS Monterey running on VMWare/Win 10
Laz 3.1  fpc 3.2.2 Ubuntu 20.04

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: TAChartListBox Autoextend possible?
« Reply #1 on: November 20, 2019, 05:28:57 pm »
No, at least not by a built-in property or method. But you could hook into the OnPopulate event of the ChartListbox which is called whenever the listbox is fully populated, iterate through the items and measure the longest string width; finally add the Chart.Legend.SymbolWidth for the series icons, and the text height for the checkbox width, plus several pixels for margins and spacings.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.ChartListbox1Populate(Sender: TObject);
  2. var
  3.   i: Integer;
  4.   w: Integer;
  5.   h: Integer;
  6. begin
  7.   w := 0;
  8.   ChartListbox1.Canvas.Font.Assign(ChartListbox1.Font);
  9.   if ChartListbox1.Canvas.Font.Size = 0 then
  10.     ChartListbox1.Canvas.Font.Size := 9;
  11.   for i:=0 to ChartListbox1.items.count-1 do
  12.     w := Max(w, ChartListbox1.Canvas.TextWidth(ChartListbox1.Items[i]));
  13.   h := ChartListbox1.Canvas.TextHeight('Tg');
  14.   w := w + Chart1.Legend.SymbolWidth + h + 20;
  15.   ChartListbox1.Width := w;
  16. end;

AL

  • Sr. Member
  • ****
  • Posts: 261
Re: TAChartListBox Autoextend possible?
« Reply #2 on: November 21, 2019, 12:35:57 am »
Thank you very much, work perfect.
I only had to slightly adjust  line 14 to:

14  w := w + Chartlistbox1.Chart.Legend.SymbolWidth + h + 20; 
Laz 3.1, fpc 3.2.2, Win10
Laz 3.1  fpc 3.2.2, MacOS Monterey running on VMWare/Win 10
Laz 3.1  fpc 3.2.2 Ubuntu 20.04

 

TinyPortal © 2005-2018