Blog

All Blog Posts  |  Next Post  |  Previous Post

Undefined points in chart data

Wednesday, November 2, 2022

A while ago, we released TMS FNC Chart v2.5. The release introduced some major new features such as logarithmic scales and crosshairs. Today we are proud to present v2.6 which brings yet another major new feature: undefined points. With undefined points we add the ability to create and display series with missing data.

Getting Started

When dropping a TTMSFNCChart on the form, you immediately notice there are three series with each the same amount of points. The line runs through each point. To explain undefined points we'll focus on one series so let's remove the other 2 series first.

TMSFNCChart1.BeginUpdate;
TMSFNCChart1.Series[2].Free;
TMSFNCChart1.Series[1].Free;
TMSFNCChart1.EndUpdate;

TMS Software Delphi  Components

Adding undefined points

For the purpose of this blog, we add random data. We can do this by using the following code:

var
  I: Integer;
  p: TTMSFNCChartPoint;
begin
  TMSFNCChart1.BeginUpdate;
  TMSFNCChart1.Series[0].Points.Clear;
  for I := 0 to 10 do
  begin
    p := TMSFNCChart1.Series[0].Points.Add;
  end;
  TMSFNCChart1.EndUpdate;
end;

Now, we want to hide the data for point index 3 and 4.

var
  I: Integer;
  p: TTMSFNCChartPoint;
begin
  TMSFNCChart1.BeginUpdate;
  TMSFNCChart1.Series[0].Points.Clear;
  for I := 0 to 10 do
  begin
    p := TMSFNCChart1.Series[0].Points.Add;
    p.Undefined := I in [3, 4];
  end;
  TMSFNCChart1.EndUpdate;
end;

For the line chart specifically, this creates a hole, interrupting the line and creating 2 separate lines.

TMS Software Delphi  Components

Virtual undefined data

The chart supports providing data in a virtual way, by implementing 2 events: OnGetNumberOfPoints and OnGetPoint. When data comes from a predefined data-structure, we can easily add undefined points by using the following code.

TMyData = class
private
  FUndefined: Boolean;
  FValue: Double;
public
  constructor CreateWithValue(AValue: Double);
  constructor CreateUndefined;
  property Value: Double read FValue;
  property Undefined: Boolean read FUndefined;
end;
TMSFNCBarChart1.BeginUpdate;
FData := TObjectList<TMyData>.Create;
FData.Add(TMyData.CreateWithValue(120));
FData.Add(TMyData.CreateWithValue(150));
FData.Add(TMyData.CreateWithValue(220));
FData.Add(TMyData.CreateWithValue(40));
FData.Add(TMyData.CreateUndefined);
FData.Add(TMyData.CreateWithValue(85));
FData.Add(TMyData.CreateUndefined);
FData.Add(TMyData.CreateWithValue(60));
TMSFNCBarChart1.EndUpdate;
procedure TForm1.TMSFNCBarChart1GetNumberOfPoints(Sender: TObject;
  ASerie: TTMSFNCChartSerie; var ANumberOfPoints: Integer);
begin
  if Assigned(FData) then
    ANumberOfPoints := FData.Count;
end;

procedure TForm1.TMSFNCBarChart1GetPoint(Sender: TObject;
  ASerie: TTMSFNCChartSerie; AIndex: Integer;
  var APoint: TTMSFNCChartPointVirtual);
begin
  if (AIndex >= 0) and (AIndex <= FData.Count - 1) then
  begin
    APoint.YValue := FData[AIndex].Value;
    APoint.Undefined := FData[AIndex].Undefined;
  end;
end;

As you can see in the screenshot below, there are 2 values missing for point 4 and 6. For the bar chart specifically, the bars are missing for the 2 undefined points.

TMS Software Delphi  Components

Supported types

All series types are supported except for ctStackedArea, ctStackedPercentageArea. Below are 2 examples of a pie and an area chart applied on the above code. The area chart is rendered with a hole and the pie chart is missing 2 slices.

TMS Software Delphi  Components

TMS Software Delphi  Components

Feedback

As always, these kinds of new features are based on customer feedback. It's important to provide feedback to us so we can make our products better. Feel free to leave a comment on what you think about this feature, or if you have other suggestions for TMS FNC Chart.



Pieter Scheldeman




This blog post has received 1 comment.


1. Wednesday, November 2, 2022 at 1:53:27 PM

Great addition - many thanks

Baecker Gernot




Add a new comment

You will receive a confirmation mail with a link to validate your comment, please use a valid email address.
All fields are required.



All Blog Posts  |  Next Post  |  Previous Post