Hello,
Looking at the final data in the series I see at the index 18, instead of reusing the preceding value (index 17), it takes the value of a couple of indices above (index 15):

- JFKUAgWmmP.png (79.73 KiB) Viewed 1636 times
If you debug the final
lChartStepDowns
loop, where you add the repeated values, you'll see you are getting the stepDowns for values 8, 5 and 15, in that order.
- Adding a repeated value for the 8 affects the indexes >8. Ok.
- Adding a repeated value for the 5 affects the indexes >5. The operation above didn't affect this. Ok.
- Adding a repeated value for the 15 affects the indexes >15. The operations above affect this because now at the index 15 you have the XValue 13 and YValue 11.627.45.
To fix this, you only have to sort the
lChartStepDowns
before the loop so you add repeated loops from the end:
Code: Select all
uses Generics.Defaults;
var IntegerComparer: IComparer<Integer>;
function CompareStepDowns(const ALeft, ARight: TChartStepDown): Integer;
begin
Result:=IntegerComparer.Compare(ALeft.FX, ARight.FX);
end;
procedure TForm2.UpdateChart(aChart: TChart);
//...
var
Comparer: IComparer<TChartStepDown>;
//...
Comparer:=TComparer<TChartStepDown>.Construct(CompareStepDowns);
lChartStepDowns.Sort(Comparer);
for I := lChartStepDowns.Count-1 downto 0 do begin
lChartStepDown := lChartStepDowns[I];
//...
end;