[SOLVED] Sorting an Array for a lineSeries lazarus / 55-TAChart ---------------------------------------------------------------------- donnie · 2017-01-25 12:22 Hi there again, I have an array with two fields x,y which I call it tpnt. 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 type   tpnt = record      x : TFloat;      y: TFloat;   end;      and as I put some values in it is not sorted. The thing is that I must sort it to the x field. the code I use is simple and after that I draw it as well 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 n := High(PositionArray);  repeat    newn := 0;    for i := 1 to n   do    begin        if PositionArray[i-1].x > PositionArray[i].x then        begin            tempx := PositionArray[i-1].x;            tempy := PositionArray[i-1].y;            PositionArray[i-1].x := PositionArray[i].x;            PositionArray[i-1].y := PositionArray[i].y;            PositionArray[i].x:= tempx;            PositionArray[i].y:= tempy;            newn := i;          end;      end ;    n := newn;  until n = 0;    for i := Low(PositionArray) to High(PositionArray) do  begin    xaxis := PositionArray[i].x;    yaxis := PositionArray[i].y;    newlineXTHsorted.AddXY(xaxis, yaxis);  end;     Is there something in order not to sort the array myself and leave this sorting for the lineseries? I mean if this can hapen with the tachart itself. ---------------------------------------------------------------------- wp · 2017-01-25 18:33 If you don't want to sort the primary data array it would be best to add all x,y pair to the built-in ListSource of the series. And this can be sorted: 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 type  TPnt = record x,y: TFloat;end; var  PositionArray: array of TPnt; // after you have all your data and when you want to create a plot:for i:=0 to High(PositionArray) do  Chart1LineSeries1.AddXY(PositionArray[i].x, PositionArray[i].y);Chart1LineSeries1.ListSource.Sort; The attached demo creates x values in random order and adds them to a lineseries. Once the series is sorted (Checkbox "Sorted") these random values are sorted automatically into the right location. ---------------------------------------------------------------------- donnie · 2017-01-26 09:36 Yeap, That's what I mean. Fast and easy. Thanks once again wp.