Difference between revisions of "TAChart Runtime FAQ"
From Free Pascal wiki
Jump to navigationJump to search (→How to iterate through the series of a chart?: Iterator CustomSeries) |
(→How to delete/hide a series at runtime?: less well-known units) |
||
Line 61: | Line 61: | ||
[[Category:TAChart]] | [[Category:TAChart]] | ||
+ | |||
+ | == Miscellaneous == | ||
+ | |||
+ | === What can I do to avoid compiler error ''"Identifier not found 'TDoublePoint'"''? === | ||
+ | <code>TDoublePoint</code> is declared in unit <code>TAChartUtils</code>, add it to the <code>uses</code> clause of the unit. It also contains the declaration of | ||
+ | * <code>TDoubleRect</code> which is needed for chart extents. | ||
+ | |||
+ | Other declarations, often not found when working with run-time code, are | ||
+ | * <code>TSeriesMarksStyle</code> for the <code>Style</code> of axis and series <code>Marks</code> --> in unit <code>TAChartUtils</code> | ||
+ | * <code>TSeriesPointerStyle</code> for the series pointer styles, e.g. <code>psCircle, psRectangle</code> --> in unit <code>TATypes</code> | ||
+ | * geometrical functions (creation of <code>TDoublePoint</code> and <code>TDoubleRect</code>, overloaded operators for <code>TPoint</code> and <code>TDoublePoints</code>) are in unit <code>TAGeometry</code> |
Revision as of 00:37, 30 January 2018
This wiki is trying to answer frequently asked questions related to usage of TAChart at runtime
Series
How to add a series at runtime?
Just create the series, set its properties and call the chart method AddSeries
uses
TATypes, TASeries;
function AddLineSeries(AChart: TChart; ATitle: String): TChartSeries;
begin
Result := TLineSeries.Create(AChart.Owner);
with TLineSeries(Result) do
begin
// Series title for the legend
SeriesTitle := ATitle;
// Show data point markers (red fill color, black border)
ShowPoints := true;
Pointer.Brush.Color := clRed;
Pointer.Pen.Color := clBlack;
Pointer.Style := psCircle;
// Show red line segments connecting the data points
ShowLines := true;
LinePen.Style := psSolid;
SeriesColor := clRed;
end;
// Add new series to the chart
AChart.AddSeries(Result);
end;
How to iterate through the series of a chart?
The series are accessible via the array-like property Series
of the chart. Note that this returns only the most fundamental series type, TBasicChartSeries, and a type-cast may be necessage before being able to access the series properties.
The following example re-colors all line series in red:
uses
TASeries;
var
i: Integer;
begin
for i := 0 to AChart.SeriesCount-1 do
if AChart.Series[i] is TLineSeries then
TLineSeries(AChart.Series[i]).SeriesColor := clRed;
end;
If you prefer the more modern iterators you can use the syntax
uses
TASeries, TAEnumerators;
var
ser: TCustomSeries;
begin
for ser in CustomSeries(AChart) do
TLineSeries(ser).Series.Color := clRed;
end;
How to delete/hide a series at runtime?
- If you don't need the series any more just destroy it:
series.Free
. - If you want to keept it for other usage, for example to insert it into another chart, call
Chart.DeleteSeries(series)
. - If you want to hide it, but keep it in the chart, set the property
Active
of the series tofalse
.
Miscellaneous
What can I do to avoid compiler error "Identifier not found 'TDoublePoint'"?
TDoublePoint
is declared in unit TAChartUtils
, add it to the uses
clause of the unit. It also contains the declaration of
TDoubleRect
which is needed for chart extents.
Other declarations, often not found when working with run-time code, are
TSeriesMarksStyle
for theStyle
of axis and seriesMarks
--> in unitTAChartUtils
TSeriesPointerStyle
for the series pointer styles, e.g.psCircle, psRectangle
--> in unitTATypes
- geometrical functions (creation of
TDoublePoint
andTDoubleRect
, overloaded operators forTPoint
andTDoublePoints
) are in unitTAGeometry