Search code examples
delphidelphi-xeteechart

TeeChart TLineSeries - Is it possible to draw multiple lines per series?


Is it possible to draw multiple lines with a single TLineSeries using TeeChart? I would like to specify a field in the dataset that the series should group by, drawing one line per group. Or is this not possible and a series should be added to the chart for each group/line that should be displayed?


Solution

  • You could achieve it setting XValues.Order to loNone and adding a null point each time you want to start a new line. However, to speed up drawing and point handling TFastLineSeries uses the same color (SeriesColor) for all points. If you want to use diferent colors for individual points you should use the TLineSeries instead.

    uses Series;
    
    procedure TForm1.FormCreate(Sender: TObject);
    var i, j: Integer;
    begin
      Chart1.View3D:=false;
      Chart1.Legend.Visible:=false;
    
      with Chart1.AddSeries(TFastLineSeries) as TFastLineSeries do
      begin
        XValues.Order:=loNone;
        TreatNulls:=tnDontPaint;
        for i:=0 to 4 do
        begin
          if i>0 then AddNullXY(0,0);  //start a new line
    
          AddXY(0,Random*1000);
          for j:=1 to 24 do
            AddXY(j, Chart1[0].YValue[Chart1[0].Count-1] + random*10 - 5);
        end;
      end;
    end;
    

    Anyway, I don't see why one would like to do the above instead of creating several TFastLine series.

    --

    Best Regards,

    Yeray Alonso

    Steema Support Central