Page 1 of 1

[LineSeries] How to insert Y values at specific X positions?

Posted: Wed Apr 20, 2016 4:50 pm
by 16577883
Hello :)

I'm trying to realize an optimization for handling alot of data and adding a custom zoom.

This is the original chart, where only each 9th point is being drawn.

Image

If I zoom in ...

Image

... the following happens:

Image

Image

As you can see, the Chart draws a line from the last X value (14.000'ish) to the zoom point and adds new values to that position, simply overdrawing the previous, instead of "inserting" the values at this position.
I already followed a solution given by NarcĂ­s, but it isn't working. http://www.teechart.net/support/viewtopic.php?t=5127

Code: Select all

procedure TFrame_ElementDetails.Chart_ObservationZoom(Sender: TObject);
var
  Chart: TChart;
  i, IndexFrom, IndexTo: Cardinal;
  LineColor: TColorRec;
  S: String;
  Ls: TLineSeries;
  // ...
begin
  if not (Sender is TChart) or not Assigned(FObserver) then
    Exit;

  // ...
  Chart := TChart(Sender);
  Ls := TLineSeries(Chart.Series[0]);
  IndexFrom := Floor(Chart.BottomAxis.CalcPosPoint(Chart.Zoom.X0));
  IndexTo := Ceil(Chart.BottomAxis.CalcPosPoint(Chart.Zoom.X1));

  Chart.AutoRepaint := FALSE;
  try
    for i := IndexFrom to IndexTo do
      begin
        Data := DataList[i];
        LineColor := GetChartValueColor(Data.Values[0], Data.Sigma[4]);
        S := FormatDateTime('ddddd', Data.Timestamp) + #13#10 +
          FormatDateTime('tt', Data.Timestamp);
        TLineSeries(Chart_Observation.Series[0]).AddXY(i, Data.Values[0], S,
          LineColor);
      end;
  finally
    Chart.AutoRepaint := TRUE;
    Chart.Refresh;
  end;
end;
How can I solve this please?

Re: [LineSeries] How to insert Y values at specific X positions?

Posted: Thu Apr 21, 2016 9:28 am
by 16577883
Ok, got it solved. I had "LineSeries.XValues.Order := loNone;" Setting it to "Ls.XValues.Order := loAscending;" actually works fine. :)

Re: [LineSeries] How to insert Y values at specific X positions?

Posted: Thu Apr 21, 2016 1:24 pm
by yeray
Hello,

I'm glad to hear you found how to solve it! :)