Dynamically adding/removing TChartStye lazarus / 55-TAChart ---------------------------------------------------------------------- mtanner · 2017-01-23 15:38 I'm drawing a stacked bat chart, with a single bar and a variable number of "slices". So a bit like a pie chart but as a vertical rectangle. I find I need to dynamically add TChartStyle items to the TChartStyles component I am using. This seems necessary ij order to get the legend having the correct number of entries. My problem is that I cannot find the relevant "Clear" and "Add" methods for the TChartStyles. Each time the chart is drawn I want to delete all styles from the TChartStyles and then add a TChartStyle for eacj slice that I am adding to the bar. Can you tell me the methods to do this please? ---------------------------------------------------------------------- wp · 2017-01-23 17:38 The TChartStyles component houses a collection named Styles which contains all styles. Therefore, you simply call ChartStyles1.Styles.Add to create a new ChartStyle and add it to the collection. The Add method returns a pointer to the newly created collectionitem; you must cast it TChartStyle to get access to its properties. In order to delete a style just call the Delete method of the collection with the index of the corresponding style (ChartStyles1.Styles.Delete(index)): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  style: TChartStyle;...  style := TChartStyle(ChartStyles1.Styles.Add);  style.Brush.Color := clBlue;  style.Text := 'Some legend text';...  ChartStyles1.Styles.Delete(index_to_be_deleted); In the attachment, there's a little demo which adds stacked bars at runtime and allows deletion of the stack level selected in a listbox. ---------------------------------------------------------------------- mtanner · 2017-01-23 22:34 Thanks for that. All working fine now. ---------------------------------------------------------------------- wp · 2017-01-24 11:56 I added the demo to the examples coming with TAChart (tachart/demo/runtime/chartstyles) so that it won't get buried in the forum. Probably more to follow in the runtime folder...