Search code examples
delphiplotteechart

change in sequence of the points using AddXY in Delphi


Using a TChart line graph I want to allow users to optionally rotate the plots. This is to say it will draw (Y,-X) instead of (X,Y), but when the plots are drawn, the sequence of point changes and points connect to each other based on increasing values of first argument. You can see the results in the following pictures:

Normal

Normal Graph

Rotated

Rotated Graph

I use .AddXY to add the points to the series that I want to plot:

TChartGraph.Series[TheSeries].AddXY(GetXorY(TheValue),-SegOrDepthLiqSI)

Any idea idea how can I force the code to connect the points in the order that I want?


Solution

  • This is actually poorly documented. When adding XY values the default behaviour is to sort the value pairs by x-value. To disable this for degenerate graphs which must link in the added-order you simply do :

    Chart1.Series[0].XValues.Order := loNone;
    

    This property must be set before adding values to the series. You can also set this property at design time here :

    enter image description here