Hi,
I have created an application that monitors the CPU usage of a specific application. I would like to represent that data in a chart/graph in real-time.
What I'm looking for is a line chart that starts on the right hand side and moves across the screen. Previous points would disappear off the left hand side of the chart as the chart fills up and new points are added to the right hand side (similar to what happens in Resource Monitor).
Is this possible with FNC Chart? Or maybe with the VCL Chart?
Thanks.
= Steve
Hi,
this is possible. You can dynamically "feed" an array of points to the chart with the OnGetNumberOfPoints and the OnGetPoint events in TMS FNC Chart
Thanks Pieter,
Do you have a demo or example?
Thanks.
= Steve
This is a complete code sample that demonstrates this (FMX)
unit Unit83;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.TMSFNCChart;
type
TForm83 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
c: TTMSFNCChart;
FPointArray: array of Double;
public
{ Public declarations }
procedure DoTimer(Sender: TObject);
procedure DoGetNumberOfPoints(Sender: TObject; ASerie: TTMSFNCChartSerie; var ANumberOfPoints: Integer);
procedure DoGetPoint(Sender: TObject; ASerie: TTMSFNCChartSerie; AIndex: Integer; var APoint: TTMSFNCChartPointVirtual);
end;
var
Form83: TForm83;
implementation
{$R *.fmx}
procedure TForm83.DoGetNumberOfPoints(Sender: TObject;
ASerie: TTMSFNCChartSerie; var ANumberOfPoints: Integer);
begin
ANumberOfPoints := Length(FPointArray);
end;
procedure TForm83.DoGetPoint(Sender: TObject; ASerie: TTMSFNCChartSerie;
AIndex: Integer; var APoint: TTMSFNCChartPointVirtual);
begin
APoint.YValue := FPointArray[AIndex];
end;
procedure TForm83.DoTimer(Sender: TObject);
begin
c.BeginUpdate;
SetLength(FPointArray, Length(FPointArray) + 1);
FPointArray[Length(FPointArray) - 1] := Random(1000);
if Length(FPointArray) >= c.Series[0].MaxX then
begin
c.Series[0].MinX := c.Series[0].MinX + 1;
c.Series[0].MaxX := c.Series[0].MaxX + 1;
end;
c.EndUpdate;
end;
procedure TForm83.FormCreate(Sender: TObject);
var
t: TTimer;
begin
c := TTMSFNCChart.Create(Self);
c.Parent := Self;
c.OnGetNumberOfPoints := DoGetNumberOfPoints;
c.OnGetPoint := DoGetPoint;
c.Series.Add;
t := TTimer.Create(Self);
t.OnTimer := DoTimer;
t.Interval := 1000;
t.Enabled := True;
end;
end.
That's fantastic! Thank you very much Pieter.
= Steve