Notification when adding a new series to a TChart lazarus / 55-TAChart ---------------------------------------------------------------------- wp · 2011-07-05 16:39 As discussed in another thread I am writing a TChartListbox for being able to show/hide series of a TChart. In order to get notified for changes in the series I added a TListener to the component. Code: [Select]  FListener := TListener.Create(@FChart, @SeriesChanged); "SeriesChanged" presently just calls "Populate" which reads all series into the listbox: Code: [Select]procedure TChartListbox.Populate; var   i : integer; begin   try     FreeAndNil(FLegendItems);     Items.BeginUpdate;     Items.Clear;     if (FChart <> nil) then begin       FLegendItems := GetLegendItems;       for i:=0 to FLegendItems.Count-1 do begin         Items.AddObject('', FLegendItems[i]);         Checked[i] := TCustomChartSeries(FLegendItems[i].Owner).Active;       end;     end;   finally     Items.EndUpdate;   end; end There is a button on the form which adds a new series with random data to the chart. Code: [Select]procedure TForm1.Button1Click(Sender:TObject); var   ser : TLineSeries; begin   RandomChartSource.RandSeed := random(65000);   ser := TLineSeries.Create(Chart);   ser.Source := RandomChartSource;   ser.SeriesColor := rgbToColor(random(255), random(256), random(256));   ser.Title := Format('Series %d', [Chart.SeriesCount]);   Chart.AddSeries(ser); end; The new series appeas in the chart immediately. In the listbox, however, it appears only after clicking the button for a second time. There must be something in the listening/broadcasting mechanism which I do not understand. What am I doing wrong? ---------------------------------------------------------------------- Ask · 2011-07-05 17:09 Try r31568. The Broadcaster will react on any visible change to a chart, from zooming to adding a point. Unfortunately, there are quite a few potential events that may change legend appearance -- such as changing SeriesColor etc., so filtering relevant events seems impossible to me. ---------------------------------------------------------------------- wp · 2011-07-06 09:03 Yes, now the listbox reacts immediately. Does the broadcaster transmit supplementary information on what has been changed in the chart? I try to avoid building the listbox items each time data were added to a series by means of AddXY. ---------------------------------------------------------------------- Ask · 2011-07-06 10:03 Notification event receives an argument (Sender), containing the object which initiated the change. In particular, adding points results in Sender being equal to the corresponding chart source. However, I am not sure there is a robust way to distinguish which changes will accept the legend look -- for example, somebody can write a legend item which encodes the size of the series.