Working with FNCChart

Good morning to all,
i'm trying to work with FNCChart and, im my case, is not so easy.
What i need is show some data (money value) reported to 24h per selected day.
Now i have one arrary [0..23] that rapresent the 24 hours of a day.
My chart is inizialized with

procedure TFM.ImpostaGrafico;
var S  : TTMSFNCChartSerie;
    I  : Integer;
    PT : TTMSFNCChartPoint;
begin
  Chart1.BeginUpdate;
  Chart1.Clear;
  S := Chart1.Series.Add;
  S.Mode := smStatistical;
  S.AutoXRange := arEnabled;
  S.AutoYRange := arEnabledZeroBased;
  for I := 0 to Length(FPointArray) - 1 do
  begin
    PT := S.Points.Add;
    PT.XValueText := FormatFloat('#0',I + 1);
    PT.YValue:=10000;
  end;
  Chart1.EndUpdate;
end;

and the result is

i setted this event

procedure TFM.Chart1GetNumberOfPoints(Sender: TObject;
  ASerie: TTMSFNCChartSerie; var ANumberOfPoints: Integer);
begin
  ANumberOfPoints := Length(FPointArray);
end;

procedure TFM.Chart1GetPoint(Sender: TObject; ASerie: TTMSFNCChartSerie;
  AIndex: Integer; var APoint: TTMSFNCChartPointVirtual);
begin
  if (AIndex >= 1) and (AIndex <= Length(FPointArray)) then
    APoint.YValue := FPointArray[AIndex];
end;

I try to add some points as an example setting the values for hours as
hours 8 (values from 8.00 to 8.59) and 10 (values from 10.00 to 10.59) as

FPointArray[8]:=800
FPointArray[10]:=650

The result is

The serie is type ctXYLine.
How i can do in order to start the line not from 7 but from 8 (vertical to his value)??

Sorry if i do not explain well !!!

Thank you for assistance

Best regards
Daniele

Set APoint.XValue to the Index;

Good morning Pieter,
can you give a simple example on how to work in a correct way with chart?
I have this procedure to "prepare" the chart:

procedure TFM.ImpostaGrafico;
var S  : TTMSFNCChartSerie;
    I  : Integer;
    PT : TTMSFNCChartPoint;
begin
  Chart1.BeginUpdate;
  Chart1.Clear;
  S := Chart1.Series.Add;
  S.Mode := smStatistical;
  S.AutoXRange := arEnabled;
  S.AutoYRange := arEnabledZeroBased;
  FPointArray[9]:=500;
  FPointArray[10]:=650;
  FPointArray[11]:=450;
  Chart1.EndUpdate;
end;

Where

FPointArray  : array [0..23] of Double;

and to show the chart i have:

procedure TFM.Chart1GetNumberOfPoints(Sender: TObject;
  ASerie: TTMSFNCChartSerie; var ANumberOfPoints: Integer);
begin
  ANumberOfPoints := Length(FPointArray);
end;

procedure TFM.Chart1GetPoint(Sender: TObject; ASerie: TTMSFNCChartSerie;
  AIndex: Integer; var APoint: TTMSFNCChartPointVirtual);
begin
  if (AIndex >= 1) and (AIndex <= Length(FPointArray)) then
  Begin
    if FPointArray[AIndex]>0 then
    Begin
      APoint.YValue := FPointArray[AIndex];
      APoint.XValue:= AIndex;
    End;
  End;
end;

the result is this:


Please, can you help me in order to remove the lines that start at 8 t0 9 and from 11 to 12 ??

Thank you for helping me ...
Best regards
Daniele

Hi,

You can use this code

procedure TForm1.Chart1GetPoint(Sender: TObject; ASerie: TTMSFNCChartSerie;
  AIndex: Integer; var APoint: TTMSFNCChartPointVirtual);
begin
  if (AIndex >= 0) and (AIndex <= Length(FPointArray) - 1) then
  Begin
    if FPointArray[AIndex] > 0 then
    Begin
      APoint.YValue := FPointArray[AIndex];
      APoint.XValue := AIndex;
    End
    else
      APoint.Undefined := True;
  End;
end;

Good afternoon Pieter,
thank you very much for your very quick reply.
Using your suggestion what i get is this:


As you see i loose all other day hours.
The picture shows the correct result but, in the same time, i need to show the hours on x axis.
There's a way to get a chart like this ?

Thank you for your, appreciate, help.

Best regards
Daniele

Hi,

Your auto-range for the X-Axis is arEnabled, which means it will only take the valid points. change it to arDisabled and specify minimum and maximum boundaries

Hi Pieter,
thank you so much !!! ... Solved ....
I've a lot to leanr about chart !!!

Best regards
Daniele

1 Like