YOUSEFUL / DELPHI / COMPONENTS

TAtlasPlotData

The chart companion: a data source that shows a TAtlasPlot chart as a table, with one row per argument and one column per series, and writes edits back to the chart.

Non-visual component Palette: Atlas Plot Unit Atlas.VGridPlot · Inherits TAtlasGridData · Product Atlas Virtual Grid

Description

Set Plot to a TAtlasPlot. Column 0 is the argument. It shows the point labels when the first visible series has any point text, dates when the chart's argument axis is a date axis, and the number otherwise. One number column follows per series, hidden series included. Rows are the distinct arguments of all series, in ascending order. A series with no point at an argument, or with a gap there, shows a null cell. When a series has several points on one argument, the table shows the first.

Editing a value calls the series' SetY, or adds a point at that argument when the series had none. Arguments cannot be edited in the table. A blank value is refused, because a series has no way to blank a point. The chart's own rules still apply (for example, those of pie series), and a refusal arrives as EAtlasGridError with the chart unchanged.

The adapter follows the chart through the chart's change listeners, once per chart BeginUpdate/EndUpdate batch, so the chart's own events stay free for the application. When the chart is destroyed, Plot becomes nil and the table empties.

Members

MemberKindWhat it does
Createconstructor from TAtlasGridDataCreates the source with no listeners.
DestroydestructorStops listening to the chart.
ColumnTitlemethodColumn 0: the title of the chart's argument axis, or Argument when it is empty.
ColumnKindmethodColumn 0 is ckDateTime when the argument axis has DateTime set, ckText when the first visible series has any point text, and otherwise ckNumber.
ColumnReadOnlymethodTrue for column 0 (the arguments) and False for the series columns.
GetCellmethodColumn 0 holds the row's argument: as a label (the first non-empty point text at that argument, or the number as text), a date or a number.
SetCellmethodWrites a number to the series of column Column at the argument of row Row, changing the existing point or adding one.
RowOfPointmethodThe data row that shows point PointIndex of Series.
ArgumentOfRowmethodThe argument (X value) of data row Row.
PlotpropertyThe chart shown.
BeginUpdatemethod from TAtlasGridDataStarts a batch: the changes made until the matching EndUpdate reach watching grids as one notification.
EndUpdatemethod from TAtlasGridDataEnds a batch.
AddListenermethod from TAtlasGridDataRegisters a method that is called, with the source as Sender, after every change or batch.
RemoveListenermethod from TAtlasGridDataUnregisters a method.
SetTextmethod from TAtlasGridDataParses Text for the column's kind with Settings (see TAtlasCell.TryParse) and stores the result with SetCell.
CheckCellmethod from TAtlasGridDataRaises EAtlasGridError Column n does not exist or Row n does not exist unless the cell lies inside the data.
RowCountproperty from TAtlasGridDataNumber of rows.
ColumnCountproperty from TAtlasGridDataNumber of columns.
Versionproperty from TAtlasGridDataIncreases on every change, including each change inside a batch and once more when the batch ends.

Constructors

Create constructorinherited from TAtlasGridData

constructor Create(AOwner: TComponent); override;

Creates the source with no listeners. The owner frees it; grids bound to it unbind themselves when it goes.

Destructors

Destroy destructor

destructor Destroy; override;

Stops listening to the chart. The chart is not freed.

Properties

Plot property

property Plot: TAtlasPlot read FPlot write SetPlot;

The chart shown. Setting it rebuilds the table and notifies watching grids. The chart may be destroyed first; Plot then becomes nil and the table empties.

pascal
Link.Plot := Chart;

RowCount propertyinherited from TAtlasGridData

property RowCount: Integer read GetRowCount;

Number of rows.

ColumnCount propertyinherited from TAtlasGridData

property ColumnCount: Integer read GetColumnCount;

Number of columns.

Version propertyinherited from TAtlasGridData

property Version: Integer read FVersion;

Increases on every change, including each change inside a batch and once more when the batch ends. Compare two readings to tell whether anything changed.

Methods

ColumnTitle method

function ColumnTitle(Column: Integer): string; override;

Column 0: the title of the chart's argument axis, or Argument when it is empty. Other columns: the series title, or Series n when it is empty.

ColumnKind method

function ColumnKind(Column: Integer): TAtlasCellKind; override;

Column 0 is ckDateTime when the argument axis has DateTime set, ckText when the first visible series has any point text, and otherwise ckNumber. The series columns are ckNumber.

ColumnReadOnly method

function ColumnReadOnly(Column: Integer): Boolean; override;

True for column 0 (the arguments) and False for the series columns.

GetCell method

function GetCell(Column, Row: Integer): TAtlasCell; override;

Column 0 holds the row's argument: as a label (the first non-empty point text at that argument, or the number as text), a date or a number. A series column holds the point's value, or null when the series has no point there or the point is a gap.

SetCell method

procedure SetCell(Column, Row: Integer; const Cell: TAtlasCell); override;

Writes a number to the series of column Column at the argument of row Row, changing the existing point or adding one. Raises EAtlasGridError for column 0 (Arguments are edited on the chart, not in the table) and for a null or non-number cell (A series value must be a number). When the chart refuses the value, it raises with the chart's own message and the chart is unchanged. Watching grids are notified once.

pascal
Link.SetCell(1, 0, TAtlasCell.OfNumber(25));

RowOfPoint method

function RowOfPoint(Series: TAtlasPlotSeries; PointIndex: Integer): Integer;

The data row that shows point PointIndex of Series. Returns -1 when no chart is linked, the series is nil or belongs to another chart, or the index is out of range. Use it in the chart's OnPointClick, together with the grid's RowOfDataRow, to select the matching cell.

pascal
Row := Grid.RowOfDataRow(Link.RowOfPoint(Series, PointIndex));

ArgumentOfRow method

function ArgumentOfRow(Row: Integer): Double;

The argument (X value) of data row Row. Raises EAtlasGridError outside the rows.

BeginUpdate methodinherited from TAtlasGridData

procedure BeginUpdate;

Starts a batch: the changes made until the matching EndUpdate reach watching grids as one notification. Batches nest.

pascal
Orders.BeginUpdate;

EndUpdate methodinherited from TAtlasGridData

procedure EndUpdate;

Ends a batch. When the outermost batch ends and something changed, the listeners are called once. An EndUpdate without a BeginUpdate is ignored.

pascal
Orders.EndUpdate;

AddListener methodinherited from TAtlasGridData

procedure AddListener(const Listener: TNotifyEvent);

Registers a method that is called, with the source as Sender, after every change or batch. Adding the same method twice registers it once. Grids register themselves when bound, so this is for your own code.

RemoveListener methodinherited from TAtlasGridData

procedure RemoveListener(const Listener: TNotifyEvent);

Unregisters a method. Safe during a notification and after the source has begun to be destroyed.

SetText methodinherited from TAtlasGridData

procedure SetText(Column, Row: Integer; const Text: string; const Settings: TFormatSettings);

Parses Text for the column's kind with Settings (see TAtlasCell.TryParse) and stores the result with SetCell. Raises EAtlasGridError for a cell outside the data and for text that does not parse ("abc" is not a number, is not a date, is not yes or no); the stored value is unchanged. The grid's editor and Delete key write through this method with the global FormatSettings.

pascal
Orders.SetText(1, 0, '1300.75', TFormatSettings.Invariant);

CheckCell methodinherited from TAtlasGridData

procedure CheckCell(Column, Row: Integer);

Raises EAtlasGridError Column n does not exist or Row n does not exist unless the cell lies inside the data.

Examples

Show a chart as a table below it

For a chart with one bar series "Sales" labelled Jan and Feb (10 and 20), the grid shows Jan 10, Feb 20 and a total of 30. Typing 25 over Feb raises the bar and the total becomes 35; adding a point on the chart adds a row.

pascal
uses Vcl.Forms, Vcl.Controls, Atlas.Plot, Atlas.VGridPlot, Atlas.VGrid;

function LinkChart(Form: TForm; Chart: TAtlasPlot): TAtlasVirtualGrid;
var Link: TAtlasPlotData;
begin
  Link := TAtlasPlotData.Create(Form);
  Link.Plot := Chart;                        // column 0: the argument, then one column per series
  Result := TAtlasVirtualGrid.Create(Form);
  Result.Parent := Form;
  Result.Align := alBottom;
  Result.Data := Link;
  Result.Columns[1].Total := tkSum;
end;

Select the cell of a clicked bar

From the VirtualAndPlotGrid sample: assigned to the chart's OnPointClick, it selects the cell showing the clicked point, even when the table is sorted.

pascal
uses Atlas.PlotSeries, Atlas.VGridPlot, Atlas.VGrid;

procedure TVirtualPlotForm.PointClicked(Sender: TObject; Series: TAtlasPlotSeries; PointIndex: Integer);
var Row: Integer;
begin
  // The adapter gives the data row; the grid turns it into the row as shown (it may be sorted).
  Row := FChartGrid.RowOfDataRow(FChartData.RowOfPoint(Series, PointIndex));
  if Row >= 0 then FChartGrid.SelectCell(Series.Index + 1, Row);
end;

TAtlasPlot · TAtlasVirtualGrid · TAtlasGridData · EAtlasGridError

Also in Atlas Virtual Grid

TAtlasVirtualGrid · TAtlasMemoryData · TAtlasVirtualData