Recent

Author Topic: TChart: create TLineSeries  (Read 5435 times)

corpusgemini

  • New Member
  • *
  • Posts: 19
TChart: create TLineSeries
« on: August 04, 2015, 04:12:33 am »
Hello all,

I have a question about creating TLineSeries in runtime.
Several files contain some data that I want to lay out on a TChart.
The number of data columns in the files is not fixed, so I would start by creating a dynamic array of TLineSeries and then creating the TLineSeries depending on the need.
However I got somewhat stuck when managing all these TLineSeries. The array is not practical when it comes to destroying some but not all of the TLineSeries.
So I wonder if there is a better way to manage these TLineSeries... Any insight would be very welcome!

Thanks a lot,
Tony

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: TChart: create TLineSeries
« Reply #1 on: August 04, 2015, 11:25:08 am »
There is no need to store run-time generated series in an array, TChart does this for you: call Chart1.Series[index] to access any previously generated series. But note that this returns the most basic series type only, TBasicChartSeries, you'll have to type-cast to TChartSeries or even higher in the hierarchy to access the properties needed.

An example (not tested...):
Code: [Select]
var
  bser: TBarSeries;
  lser: TLineSeries;
begin
  // Generate a bar series --> this will be Chart1.Series[0]
  bser := TBarSeries.Create(Form1); 
  bser.Title := 'bar series';
  Chart1.AddSeries(bser);

  // Generate a line series  --> this will be Chart1.Series[1]
  lser := TLineSeries.Create(Form1);
  lser.Title := 'line series';
  Chart1.AddSeries(lser);

  // Set color of bar series
  TBarSeries(Chart1.Series[0]).Brush.Color := clRed;

 

 

TinyPortal © 2005-2018