1

I'm using tchart component to show the progress of a task, the progress is displayed dynamically, something like this:

enter image description here

I'm setting the max value of the bottom axis to 50, so when this value is exceeded there is no graph displayed. How I can keep showing the progress of the task dynamically by clearing the old one and start showing the new progress, I think it should be something like:

while Progress do
begin
  if series1.bottomaxis.value = maxvalue then
  Series1.clear;
end;
series1.add(x,y);

Well, this was just to explain what I want to do. So how can I keep displaying the progress without changing the max value ?

Castro Roy
  • 7,623
  • 13
  • 63
  • 97
Safa
  • 485
  • 2
  • 5
  • 24

1 Answers1

1

The easiest solution to populate series with new data is to use the AddXY method to add points to a series. A big advantage of this method is that it's very simple to use. This is the preferred method for adding points if you're plotting at real-time and the number of points shown doesn't exceed a couple of thousand. Together with TChartSeries.Delete method it provides a powerful method to do real-time plotting. The following two routines are used in one of the TeeChart examples to perform real-time scrolling of the chart. First the routine adds new points to the series, second a routine scrolls points as new data is added and deletes old unecessary points:

  // Adds a new random point to Series
  Procedure RealTimeAdd(Series:TChartSeries);
  var XValue,YValue : Double;
  begin
    if Series.Count=0 then  // First random point
    begin
      YValue:=Random(10000);
      XValue:=1;
    end
    else
    begin
      // Next random point
      YValue:=Series.YValues.Last+Random(10)-4.5;
      XValue:=Series.XValues.Last+1;
    end;
    // Add new point
    Series.AddXY(XValue,YValue);
  end;

  // When the chart is filled with points, this procedure
  // deletes and scrolls points to the left.
  Procedure DoScrollPoints(Series: TChartSeries);
  var tmp,tmpMin,tmpMax : Double;
  begin
    // Delete multiple points with a single call.
    // Much faster than deleting points using a loop.

    Series.Delete(0,ScrollPoints);

    // Scroll horizontal bottom axis
    tmp := Series.XValues.Last;
    Series.GetHorizAxis..SetMinMax(tmp-MaxPoints+ScrollPoints,tmp+ScrollPoints);

    // Scroll vertical left axis
    tmpMin := Series.YValues.MinValue;
    tmpMax = Series.YValues.MaxValue;

    Series.GetVertAxis.SetMinMax(tmpMin-tmpMin/5,tmpMax+tmpMax/5);

    // Do chart repaint after deleting and scrolling
    Application.ProcessMessages;
  end;

For more detailed information on Real-time Charting, please read the article here.

Narcís Calvet
  • 7,304
  • 5
  • 27
  • 47
  • 1
    An answer consisting of nothing but a link to an off-site location is not acceptable. If that off-site location is unavailable, the answer depending on it loses all value. The relevant portion of that off-site content should be here, in the answer itself, with the link used as an additional reference. If that isn't possible, then this should be a comment to the question instead, because it isn't an answer. – Ken White May 01 '16 at 06:15
  • 1
    @KenWhite ok, I have copìed here the most relevant part of the article according to the question. – Narcís Calvet May 02 '16 at 08:25
  • To Ken's point for copying the relevant info - the link provided to the original article is no longer valid. – Toby Jan 30 '20 at 17:57