Sign in Join
Wiki copytemporary

TAChart Demos: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11## Introduction
22
33TAChart is Lazarus' powerful charting library. It consists of numerous classes and declarations distributed over some 50 units. New users may be overwhelmed by the complexity of usage, and even experienced charters still find gems from time to time.
44
55In order to demonstrate the possibilities of TAChart a variety of demo projects has been written. They are stored in the directory `components/tachart/demo` of the Lazarus installation. However, there is no overview of these examples, and it is often quite cumbersome to find a certain application of interest. Therefore, it is the intention of this wiki page to provide some kind of catalogue of the TAChart demos. Each demo project will be accompanied by a short description and a screen shot of the program output.
66
77## Gallery
88
99Click on the **captions** to go to the description of that particular demo project. Click on the **thumbnail** to see the screenshot at normal size.
1010
1111[`file:zdemo.png`](file:zdemo.png)`                       | `[[TAChart Demos|3d]]\
1212[`file:aggpasdemo.png`](file:aggpasdemo.png)`                  | `[[TAChart Demos|aggpas]]\
1313[`file:TAChart_Animate_Demo.jpg`](file:TAChart_Animate_Demo.jpg)`        | `[[TAChart Demos|animate]]\
1414[`file:axis_customized_marks.png`](file:axis_customized_marks.png)`       | `[[TAChart Demos|axis (Page "Customized marks")]]\
1515[`file:axis_axis_groups.png`](file:axis_axis_groups.png)`            | `[[TAChart Demos|axis (Page "Axis groups")]]\
1616[`file:axis_submarks.png`](file:axis_submarks.png)`               | `[[TAChart Demos|axis (Page "Submarks")]]\
1717[`file:axis_date_and_time.png`](file:axis_date_and_time.png)`          | `[[TAChart Demos|axis (Page "Date and time")]]\
1818[`file:axis_intervals.png`](file:axis_intervals.png)`              | `[[TAChart Demos|axis (Page "Intervals")]]\
1919[`file:axis_position.png`](file:axis_position.png)`               | `[[TAChart Demos|axis (Page "Position")]]\
2020[`file:axisalign.png`](file:axisalign.png)`                   | `[[TAChart Demos|axisalign]]\
2121[`file:axistransf_linear.png`](file:axistransf_linear.png)`           | `[[TAChart Demos|axistransf (Page "Linear")]]\
2222[`file:axistransf_indep_scale.png`](file:axistransf_indep_scale.png)`      | `[[TAChart Demos|axistransf (Page "Independent scale")]]\
2323[`file:axistransf_logarithm.png`](file:axistransf_logarithm.png)`        | `[[TAChart Demos|axistransf (Page "Logarithm")]]\
2424[`file:axistransf_normal_dist.png`](file:axistransf_normal_dist.png)`      | `[[TAChart Demos|axistransf (Page "Normal distribution")]]\
2525[`file:axistransf_userdefined.png`](file:axistransf_userdefined.png)`      | `[[TAChart Demos|axistransf (Page "User defined")]]\
2626[`file:barshapesdemo.png`](file:barshapesdemo.png)`               | `[[TAChart Demos|barserieshapes]]\
2727[`file:basicdemo.png`](file:basicdemo.png)`                   | `[[TAChart Demos|basic]]\
2828[`file:bgrademo.png`](file:bgrademo.png)`                    | `[[TAChart Demos|bgra]]\
2929[`file:charteditor_dialog.png`](file:charteditor_dialog.png)`          | `[[TAChart Demos|charteditordemo]]\
3030[`file:chartsource_basic.png`](file:chartsource_basic.png)`           | `[[TAChart Demos|chartsource (Page "Basic")]]\
3131[`file:chartsource_statistics.png`](file:chartsource_statistics.png)`      | `[[TAChart Demos|chartsource (Page "Statistics")]]\
3232[`file:chartsource_derivative.png`](file:chartsource_derivative.png)`      | `[[TAChart Demos|chartsource (Page "Derivative")]]\
3333[`file:chartsource_sorting.png`](file:chartsource_sorting.png)`         | `[[TAChart Demos|chartsource (Page "Sorting")]]\
3434[`file:clonedemo-series.png`](file:clonedemo-series.png)`            | `[[TAChart Demos|clone (Page "Series")]]\
3535[`file:clonedemo-charts.png`](file:clonedemo-charts.png)`            | `[[TAChart Demos|clone (Page "Charts")]]\
3636[`file:combodemo.png`](file:combodemo.png)`                   | `[[TAChart Demos|combobox]]\
3737[`file:distancedemo-main.png`](file:distancedemo-main.png)`           | `[[TAChart Demos|distance (Page "Main")]]\
3838[`file:distancedemo-fit.png`](file:distancedemo-fit.png)`            | `[[TAChart Demos|distance (Page "Fit")]]\
3939[`file:eventsdemo.png`](file:eventsdemo.png)`                  | `[[TAChart Demos|events]]\
4040[`file:extentdemo.png`](file:extentdemo.png)`                  | `[[TAChart Demos|extent]]\
4141[`file:fitdemo.png`](file:fitdemo.png)`                     | `[[TAChart Demos|fit]]\
4242[`file:funcdemo-domain.png`](file:funcdemo-domain.png)`             | `[[TAChart Demos|func (Page "Domain")]]\
4343[`file:funcdemo-colormap.png`](file:funcdemo-colormap.png)`           | `[[TAChart Demos|func (Page "Color map")]]\
4444[`file:funcdemo-spline.png`](file:funcdemo-spline.png)`             | `[[TAChart Demos|func (Page "Spline")]]\
4545[`file:funcdemo-autoyextent.png`](file:funcdemo-autoyextent.png)`        | `[[TAChart Demos|func (Page "Auto y extent")]]\
4646[`file:funcdemo-parametric.png`](file:funcdemo-parametric.png)`         | `[[TAChart Demos|func (Page "Parametric")]]\
4747[`file:html_demo.png`](file:html_demo.png)`                   | `[[TAChart Demos|html]]\
4848[`file:legenddemo-page1.png`](file:legenddemo-page1.png)`            | `[[TAChart Demos|legend (Page "Basics")]]\
4949[`file:legenddemo-page2.png`](file:legenddemo-page2.png)`            | `[[TAChart Demos|legend (Page "OwnerDrawn"]]\
5050[`file:linedemo-fast.png`](file:linedemo-fast.png)`               | `[[TAChart Demos|line (Page "Fast drawing")]]\
5151[`file:linedemo-pointers.png`](file:linedemo-pointers.png)`           | `[[TAChart Demos|line (Page "Pointers")]]\
5252[`file:linedemo-customdrawnpointer.png`](file:linedemo-customdrawnpointer.png)` | `[[TAChart Demos|line (Page "Customdrawn pointer")]]\
5353[`file:linedemo-ongetpointerstyle.png`](file:linedemo-ongetpointerstyle.png)`  | `[[TAChart Demos|line (Page "OnGetPointerStyle event")]]\
5454[`file:linedemo-oscilloscope.png`](file:linedemo-oscilloscope.png)`       | `[[TAChart Demos|line (Page "Oscilloscope")]]\
5555[`file:linedemo-coloreach.png`](file:linedemo-coloreach.png)`          | `[[TAChart Demos|line (Page "Color each data point")]]\
5656[`file:listboxdemo.png`](file:listboxdemo.png)`                 | `[[TAChart Demos|listbox]]` `\
5757[`file:liveview.png`](file:liveview.png)`                    | `[[TAChart Demos|liveview, liveview-paned]]\
5858[`file:multidemo-bubble.png`](file:multidemo-bubble.png)`            | `[[TAChart Demos|multi (Page "Bubble")]]` `\
5959[`file:multidemo-stacked.png`](file:multidemo-stacked.png)`           | `[[TAChart Demos|multi (Page "Stacked")]]` `\
6060[`file:multidemo-boxwhisker.png`](file:multidemo-boxwhisker.png)`        | `[[TAChart Demos|multi (Page "Box-and-Whiskers")]]` `\
6161[`file:multidemo-ohlc.png`](file:multidemo-ohlc.png)`              | `[[TAChart Demos|multi (Page "OHLC")]]` `\
6262[`file:multidemo-field.png`](file:multidemo-field.png)`             | `[[TAChart Demos|multi (Page "Field")]]` `\
6363[`file:nandemo.png`](file:nandemo.png)`                     | `[[TAChart Demos|nan]]` `\
6464[`file:navigatedemo.png`](file:navigatedemo.png)`                | `[[TAChart Demos|navigate]]` `\
6565[`file:noguidemo.png`](file:noguidemo.png)`                   | `[[TAChart Demos|nogui]]` `\
6666[`file:opengldemo.png`](file:opengldemo.png)`                  | `[[TAChart Demos|opengl]]` `\
6767[`file:panesdemo.png`](file:panesdemo.png)`                   | `[[TAChart Demos|panes]]` `\
6868[`file:printdemo.png`](file:printdemo.png)`                   | `[[TAChart Demos|print]]` `\
6969[`file:radialdemo_pie.png`](file:radialdemo_pie.png)`              | `[[TAChart Demos|radial (page "Pie")]]` `\
7070[`file:radialdemo_polar.png`](file:radialdemo_polar.png)`            | `[[TAChart Demos|radial (page "Polar")]]` `\
7171[`file:rotatedemo.png`](file:rotatedemo.png)`                  | `[[TAChart Demos|rotate]]` `\
7272[`file:savedemo.png`](file:savedemo.png)`                    | `[[TAChart Demos|save]]\
7373[`file:scriptdemo.png`](file:scriptdemo.png)`                  | `[[TAChart Demos|script]]\
7474[`file:toolsdemo.png`](file:toolsdemo.png)`                   | `[[TAChart Demos|tools]]\
7575[`file:wmfdemo.png`](file:wmfdemo.png)`                     | `[[TAChart Demos|wmf]]
7676
7777## Demo folders
7878
7979### 3d
8080
8181[thumbnail|upright 1.5](/wiki-images/4/4d/Zdemo.png) The project **`zdemo`** in the folder `3d` illustrates creation of a simple 3d effect in TAChart. Some series types have a property `Depth` allowing to extrude the series into the third dimension. Using the property `ZPosition` the series can be "shifted" back and forth into the depth dimension. The same property allows to move the axes and the grid to the front.\
8282
8383### aggpas
8484
8585[thumbnail|upright 1.5](/wiki-images/1/1a/Aggpasdemo.png) For improved rendering quality, TAChart can take advantage of the fast and powerful [AggPas](http://www.crossgl.com/aggpas/) library with anti-aliased drawing and subpixel accuracy. The project `aggpasdemo` shows the necessary code to achieve this:
8686
8787- Add a `TChartGUIConnectorAggPas` to the form and assign it to the property `GUIConnector` of the form
8888- Or, use a `TPaintbox` and use the code given in `TForm1.PaintBox1Paint` in its `OnPaint` event.
8989
9090Note that this feature is not yet available in Lazarus 1.2 and requires the trunk version. Packages `AggPasLCL` and `TACharstAggPas` are needed to compile the demo.\
9191
9292### animate
9393
9494[thumbnail|upright 1.5](/wiki-images/a/a3/TAChart_Animate_Demo.jpg) The **`animatedemo`** presents animation of a bar chart. The main animation work is done by a `TCustomAnimatedChartSource` created at runtime and its `OnGetItem` event.\
9595
9696### axis
9797
9898[thumbnail|upright 1.5](/wiki-images/8/8b/Axis_customized_marks.png) The project "axis" shows some fundamental and advanced aspects of axis formatting and layout in a multi-page form:
9999
100100Page **Customized marks** demonstrates how painting of the marks of an axis can be controlled by modifying their properties, such as `Marks.LabelBrush`, `Marks.Frame`, or `Marks.LabelFont`. Highlighting of individual marks can be done by assigning a handler to the axis event `OnMarksToText`:
101101
102102``` pascal
103103procedure TForm1.ChartCustomMarksAxisList1MarkToText(var AText: String; AMark: Double);
104104begin
105105 if AMark = 3 then
106106 AText := '*' + AText + '*';
107107end;
108108```
109109
110-\
111110[thumbnail|upright 1.5](/wiki-images/6/6a/Axis_axis_groups.png) In page **Axis groups** it is shown how a chart layout with multiple axes can be created. The [[TAChart Tutorial: Multiple Panes in one Chart]] explains the required steps in detail.
112111
113112In the demo, the axes and required axis transformations are created at runtime.\
114113[thumbnail|upright 1.5](/wiki-images/3/3d/Axis_submarks.png) In the next page, **Submarks**, a minor axis is used along the x axis, and smaller labels are drawn for each tick of the minor axis. This effect is achieved by adding an additional axis to the property `Minors`. Minor axes have their own set of marks and labels.\
115114[thumbnail|upright 1.5](/wiki-images/7/73/Axis_date_and_time.png) Displaying an axis with date and time data is the subject of page **Date and time**. The series displays random data for every hour in a 10-year date range. Zoom in by clicking with the left, zoom out by clicking with the right mouse button. For every zoom level the **TDateTimeIntervalChartSource** manages to displays reasonable labels along the x axis.\
116115[thumbnail|upright 1.5](/wiki-images/f/ff/Axis_intervals.png) The most prominent feature of the demo in page **Intervals** is that the same y data are displayed on several axes with different settings of the `Intervals` property. The x axis demonstrates how the range of displayed labels can be limited by means of the axis property `Marks.Range`.\
117116[thumbnail|upright 1.5](/wiki-images/6/66/Axis_position.png) Page **Position** demonstrates that axes do not have to be at the edge of a chart. In plots of mathematical function, for examples, the axes usually run through the origin at x=0 and y=0. Modifying the property `Position` of an axis allows to place it at any position. The demo shows also how an additional axis can be added at the chart edge.
118117
119118### axisalign
120119
121120[thumbnail|upright 1.5](/wiki-images/8/86/Axisalign.png) In new TAChart versions after Lazarus 1.2.6, the chart axis has a new property `LabelSize` which - if different from `0` - overrides the automatic axis positioning mechanism. Therefore, this property can be used to align the axis lines of charts which are stacked or positioned side-by-side and in which the axis labels have different lengths.\
122121
123122### axistransf
124123
125124[thumbnail|upright 1.5](/wiki-images/9/97/Axistransf_linear.png) The subject of the project "axistransf" are axis transformations which are the key to non-linear or distorted axis scales. Several charts are combined into a multi-paged form.
126125
127126The chart on page **Linear** shows two temperature curves which are displaced for better clarity. The summer temperatures are shown as a red curve, the labels are at the left y axis; the winter temperatures are shown as a blue curve (and overlayed bar series) and have their labels on the right y axis. Both axes cover only part of the available space to separate the data.
128127
129128This effect can be achieved by using **auto-scale axis transformations**.
130129
131-\
132130[thumbnail|upright 1.5](/wiki-images/f/f4/Axistransf_indep_scale.png) The demo **Independent scale** covers the same subject.
133131
134132See [[TAChart Tutorial: Multiple Panes in one Chart]] for a detailed explanation of the steps required.\
135133[thumbnail|upright 1.5](/wiki-images/2/2b/Axistransf_logarithm.png) A plot with logarithmic axis is displayed on page **Logarithm**. The striped background layout is achieved by means of a `TChartStyles` component.\
136134[thumbnail|upright 1.5](/wiki-images/7/73/Axistransf_normal_dist.png) Page **Normal distribution** shows a series with random data, their statistical distribution follows a Normal Distribution. Using a `TCumulNormDistrAxisTransform` the cumulated probability distribution can be distorted to follow a straight line.\
137135[thumbnail|upright 1.5](/wiki-images/c/ce/Axistransf_userdefined.png) The chart on page **User defined** contains a purple vertical line which acts like a magnifier: The series is zoomed horizontally in the vicinity around this line. Dragging the line allows to blow up any part of the series.
138136
139137This local zoom effect is achieved by means of a `TUserDefinedAxisTransform`. In this transform, the axis transformation is defined by the handler of the event `OnAxisToGraph`.\
140138
141139### barseriesshapes
142140
143141[thumbnail|upright 1.5](/wiki-images/e/e4/Barshapesdemo.png) Demonstrates usage of alternative bar shapes in 3D TBarSeries.\
144142
145143### basic
146144
147145[thumbnail|upright 1.5](/wiki-images/3/3d/Basicdemo.png) Basic operation with charts and series is demonstrated in the `basicdemo` project. The demo shows
148146
149147- how to create a series at runtime and add it to the chart
150148- how to add data to a series (`series.AddXY(...)`)
151149- how to clear series (`Chart1.ClearSeries`)
152150- how to change the z position of a series (`TForm1.BringToFront`)
153151- how to show/hide axes, axis grid, titles and the legend
154152- how to invert the axis direction
155153- how to show a crosshair marker. Note, however, that usage of the reticule is deprecated now, use [[TAChart documentation|zoom tools]] instead.
156154
157-\
158-
159155### bgra
160156
161157[thumbnail|upright 1.5](/wiki-images/4/4e/Bgrademo.png) For improved rendering quality, TAChart can take advantage of the fast and powerful [[BGRABitmap]] library with anti-aliased drawing and subpixel accuracy. The project `bgrademo` shows the necessary code to achieve this:
162158
163159- Add a `TChartGUIConnectorBGRA` to the form and assign it to the property `GUIConnector` of the form
164160- Or, use a `TPaintbox` and use the code given in `TForm1.PaintBox1Paint` in its `OnPaint` event.
165161
166162Packages `bgrabitmappack` and `TAChartBgra` are needed to compile the demo.
167163
168164> **Note:** There is a special wiki page [[BGRABitmap tutorial TAChart|BGRABitmap Tutorial TAChart]] giving step-by-step instructions how to create a chart like the one in the image at the right.
169165
170-\
171-
172166### charteditordemo
173167
174168[thumbnail|upright 1.5](/wiki-images/f/f0/Charteditor_dialog.png) The **charteditordemo** project shows a gui how the user could interactively change most elements of a chart. Besides the `TDataPointClickTool`, the project relies strongly on the dedicated chart tools `TTitleFootClickTool`, `TAxisClickTool` and `TLegendClickTool` which were introduced in Lazarus v2.1.\
175169
176170### chartsource
177171
178172The demo project **chartsource** illustrates various use cases for chart source components [thumbnail|upright 1.5](/wiki-images/4/45/Chartsource_basic.png) Page **Basic'' demonstrates that the same chartsource can be attached to several series and be used in several charts. In this example data are provided by means of a `TListChartSource` and a `TRandomChartSource`.\
179173[thumbnail|upright 1.5](/wiki-images/b/b5/Chartsource_statistics.png) Page**Statistics**illustrates some applications of the `TCalculatedChartSoruce`: cumulative sums and moving average\
180174[thumbnail|upright 1.5](/wiki-images/4/4e/Chartsource_derivative.png) Page**Derivative**highlights numerical calculation and plotting of derivatives of data series using the `TCalculatedChartSource`.\
181175[thumbnail|upright 1.5](/wiki-images/4/4d/Chartsource_sorting.png) Page**Sorting''' shows how the data values of a `TUserDefinedChartSource` can be sorted by means of a `TSortedChartSource` having it as `Origin`. This is an interesting application for a `TBubbleSeries`: when the data points are sorted by radius (y value with y index 1) in descending order the bubble are drawn from back to front. Therefore, it is not possible that bubbles are completely covered by anothers.\
182176
183177### clone
184178
185179<img src="clonedemo-series.png" title="clonedemo-series.png" height="200" alt="clonedemo-series.png" /> <img src="clonedemo-charts.png" title="clonedemo-charts.png" height="200" alt="clonedemo-charts.png" />\
186180Page **Series** of the "clonedemo" demonstrates how a series can be duplicated ("cloned"):
187181
188182``` pascal
189183 bs := TBarSeries.Create(Self);
190184 bs.Assign(ChartSeries.Series[i]);
191185 bs.BarOffsetPercent := bs.BarOffsetPercent + 20;
192186 ChartSeries.AddSeries(bs);
193187```
194188
195189Cloning of a chart, on page **Charts**, is even simpler:
196190
197191``` pascal
198192 ch := Chart1.Clone;
199193```
200194
201-\
202-
203195### combobox
204196
205197[thumbnail|upright 1.5](/wiki-images/7/7b/Combodemo.png) Application of the `TChartCombobox` is demonstrated by project "combodemo". It contains a chart with a line, bar and area series and has a sidebar for editing the appearance of these series. Brush and pen styles, pen widths and line series pointer styles can be changed by using this decicated multi-featured combobox. The standard `TColorBox` is used for modifying colors.\
206198
207199### distance
208200
209201[thumbnail|upright 1.5](/wiki-images/1/1b/Distancedemo-main.png) The [[TAChart documentation|TDataPointDistanceTool]] was designed to measure the distance of data points in a chart. The **`distancedemo`** demonstrates is application.
210202
211203Page **Main** allows to play with the main parameters of the tool. Use the left button to drag a measurement bar across the screen. The mouse-down event determines the starting point, while during dragging the end point is defined by the current mouse position. The distance is displayed in a label above the measurement line. The label can be turned off by setting the tool's `Marks.Visible` to `false`. Rotation of the label along with the measurement bar is controlled by some of the tool's `Options`. The properties `DataPointModeStart` and `DataPointModeEnd` determine whether the measurements starts or ends, respectively, at arbitrary points in the chart (`dpmFree`), or only at data points (`dpmSnap` or `dpmLock`, where `dpmLock` means that the measurement line is only visible when the mouse is near data points, in case of `dpmSnap` it is always visible but jumps to the next data point when the mouse gets close enough).
212204
213-Press the <span class="kbd">SHIFT</span> key while the left mouse button is down to zoom into the chart by a given factor; zoom returns when <span class="kbd">SHIFT</span> is released (code in `TForm1.ctDistance1BeforeKeyDown`).
205+Press the `SHIFT` key while the left mouse button is down to zoom into the chart by a given factor; zoom returns when `SHIFT` is released (code in `TForm1.ctDistance1BeforeKeyDown`).
214206
215-\
216207[thumbnail|upright 1.5](/wiki-images/1/1e/Distancedemo-fit.png) Page **Fit** shows a more advanced application of the distance tool. It uses its `OnGetDistanceText` event to fit a polynomial to the data between the start and end points of the measurement line. Fitting is done by means of a `TFitSeries`. The radiobuttons at the top ("Mean", "slope", "find peak") determine the degree of the fitted polynomial (0, 2, or 2, respectively). The fitted curved is drawn between the end points of the measurement line. For the code, see `TForm1.ctFitDataPointDistanceTool1GetDistanceText`.
217208
218209This kind of measurement is initiated by dragging with the right mouse button, while the left-drag controls a standard zooming process.
219210
220211(Note that this part of the demo is not working properly in Lazarus 1.2).
221212
222-\
223-
224213### events
225214
226215[thumbnail|upright 1.5](/wiki-images/3/31/Eventsdemo.png) TAChart exposes several events to control the appearence of the chart beyond the properties provided in the object inspector. The project `eventdemo` shows the effect of three typical events:
227216
228217- `TChart.OnBeforeDrawBackground` is called before painting the entire background rectangle of the chart. The demo shows how the background can be drawn as a gradient.
229218- `TChart.OnBeforeDrawBackWall` is a possibilty to replace painting of the backwall of the chart by a user-provided procedure (the "backwall" is the rectangle enclosed by the chart axes). Here, the backwall is drawn as another gradient.
230219- `BarSeries.OnBeforeDrawBar` allows to intercept the drawing process of a bar series. In the demo every other bar is drawn in a different fill style.
231220
232221All events provide a parameter `ADoDefaultDrawing` to skip the built-in drawing procedure if set to `false`. In the BarSeries example the 5th bar is dropped by this way.\
233222
234223### extent
235224
236225[thumbnail|upright 1.5](/wiki-images/b/b6/Extentdemo.png) The project `extentdemo` shows how the extent of a chart, i.e. the start and end of each axis, can be modified (properties `Chart.Extent.XMin`, `Chart.Extent.UseXMin`, etc.).
237226
238227In addition the demo provides code how to setup an extent history which is interesting for undoing extent changes by zooming and panning (see tutorial on "[[TAChart Tutorial: ColorMapSeries, Zooming|ColorMapSeries, zooming]]").\
239228
240229### fit
241230
242231[thumbnail|upright 1.5](/wiki-images/1/1f/Fitdemo.png) Basic fitting of equations to data by means of `TFitSeries` is illustrated by project **`fitdemo`**. The demo shows
243232
244233- how to select the fitting function and the number of fitting parameters (`TFitSeries.FitEquation`, `TFitSeries.ParamCount`).
245234- how to restrict the data range for fitting (`TFitSeries.FitRange`)
246235- how to extract the values of the fitted parameters (`TFitSeries.Param[]`)
247236
248237In addition, the usage of logarithmic x and/or y axes is demonstrated.
249238
250239> **Note:** These topics are explained in some detail in the tutorial on [[TAChart Tutorial: ListChartSource, Logarithmic Axis, Fitting|ListChartSource, logarithmic axis and fitting]].
251240
252-\
253-
254241### func
255242
256243[thumbnail|upright 1.5](/wiki-images/5/5a/Funcdemo-domain.png) The project **`funcdemo`** gives examples of the usage of function series.
257244
258245The first page of this multi-tab project, **Domain**, demonstrates the [[TAChart documentation|TFuncSeries]]. This series plots a mathematical function. The function values are passed to the series by means of an event handler for `OnCalculate`. This series type has the advantage that the plot is always smooth independent of zooming. The function `y=1/sin(x)` drawn in the screenshot at the right is not defined for integer multiples of `pi`. Therefore, standard output draws vertical connection lines at these points. This artefact can be avoided by adding the points with undefined function values to the `DomainExclusions` of the series. Click at "Domain" to see this effect.\
259246[thumbnail|upright 1.5](/wiki-images/b/b6/Funcdemo-colormap.png) The [[TAChart documentation|TColorMapSeries]] shown on page **Color map** is similar to `TFuncSeries`, however, it requires an x and y value to calculate the function value z which is encoded as a color. The calculation is done again in the event handler for `OnCalculate`. The colors are assigned to the z values by means of a ListChartSource which is assigned to the `ColorSource` property of the series.
260247
261248> **Note:** The tutorial [[TAChart Tutorial: ColorMapSeries, Zooming|ColorMapSeries, Zoomin]] explains in detail how the ColorMapSeries is applied.
262249
263-\
264250[thumbnail|upright 1.5](/wiki-images/0/0c/Funcdemo-parametric.png) Page **Parametric** shows another function series requiring an `OnCalculate` event handler, the `TParametricCurveSeries`. Here, a single parameter (`t`) is used to calculate the `x` and `y` values. The example shows the parametric function defined by\
265251`x(t) = cos(a*t) - cos(b*t)^j`\
266252`y(t) = sin(c*t) - sin(d*d)^k`.\
267253[thumbnail|upright 1.5](/wiki-images/4/4b/Funcdemo-spline.png) The [[TAChart documentation|TCubicSplineSeries]] shown on page **Spline** is similar to a standard `TLineSeries` (black), but the data points are not connected by straight line segments, but by smooth cubic [spline](http://en.wikipedia.org/wiki/Spline_%28mathematics%29) curves (bright blue). The [[TAChart documentation|TBSplineSeries]] (green) is similar, but the spline does not pass through the data points and, therefore, achieves even better smoothing.\
268254[thumbnail|upright 1.5](/wiki-images/6/6d/Funcdemo-autoyextent.png) Page **Auto y extent** gives a solution to the problem that it is normally not possible to automatically adjust the y axis to the extent of data values. `TFuncSeries` was equipped with a property `ExtentAutoY` which has to be enabled for this purpose.\
269255
270256### html
271257
272258[thumbnail|upright 1.5](/wiki-images/5/50/Html_demo.png) Embedding of html tags and entities in TAChart text elements is demonstrated by the project **`html`**. This feature is activated by setting the `TextFormat` of the corresponding text element to `tfHTML`. The codes used can be show by checking the corresponding checkboxes; the title of the x axis, for example, is written as `'Angle &alpha;, &deg;`'.
273259
274260The buttons "Copy to clipboard", "Save to WMF" and "Save to SVG" demonstrate that this special formatting is retained when copying a chart to the clipboard or when saving it to a graphics file.
275261
276-\
277-
278262### legend
279263
280264[thumbnail|upright 1.5](/wiki-images/3/35/Legenddemo-page1.png%E2%80%8E) The project **`legenddemo`** demonstrates how the legend of the TChart component can be used and modified. (Please note that after Lazarus version 1.2 the project window contains two pages; in older versions, only the first page is available).
281265
282266Page **Basic** demonstrates fundamental work with the legend:
283267
284268- showing series names (`series.Legend.Multiplicity = lmSingle`)
285269- showing series data (`series.Legend.Multiplicity = lmPoint`, demonstrated for the pie series)
286270- owner-drawing series icons for the legend by means of the event `OnDrawLegend` of a series (see `procedure Chart1FuncSeries1DrawLegend`)
287271- using legend group titles (`Chart.Legend.GroupTitles`)
288272- manually adding legend items (event `series.Legend.OnCreate`, demonstrated for `Chart1FuncSeries1`). Note the workaround for a bug in `FormCreate`.
289273- run-time modification of properties for positioning of the legend.
290274
291-\
292275[thumbnail|upright 1.5](/wiki-images/e/ee/Legenddemo-page2.png%E2%80%8E) The second page (**OwnerDraw**) explains how the legend can be drawn as a gradient bar. For this purpose an event handler must be written for the chart's event `OnDrawLegend`. The gradient is drawn by calling the following procedure:
293276
294277``` pascal
295278procedure DrawGradient(ADrawer: IChartDrawer; ARect: TRect;
296279 AStartColor, AEndColor: TColor);
297280var
298281 y,h: Integer;
299282 c: TColor;
300283begin
301284 h := ARect.Bottom - ARect.Top;
302285 if h <= 0 then exit;
303286 for y := ARect.Bottom-1 downto ARect.Top do begin
304287 c := InterpolateRGB(AStartColor, AEndColor, (ARect.Bottom - y) / h);
305288 ADrawer.SetPenParams(psSolid, c);
306289 ADrawer.Line(ARect.Left, y, ARect.Right, y);
307290 end;
308291end;
309292```
310293
311-\
312-
313294### line
314295
315296[thumbnail|upright 1.5](/wiki-images/a/a8/Linedemo-fast.png) The `linedemo` illustrates some aspects of line series.
316297
317298Page **Fast drawing**:
318299
319300- Change the selection of the combobox to switch between different `LineType`s of the series. The screen shot at the right is created with the setting `LineType = ltStepXY`.
320301- Create a 3D look by checking the option "3D".
321302- Interchange the `x` and `y` axes by checking "Rotated".
322303- Quickly add 600,000 data points and measure the time for a refresh.
323304
324-\
325305[thumbnail|upright 1.5](/wiki-images/7/7c/Linedemo-pointers.png)
326306
327307Page **Pointers** shows a list of all pointers that are available for data point markers. The chart is created by using a lineseries with three data points for each pointer `Style`. The name of the style and a different color have been assigned to the center data point in the AddXY method of the series. The size of the pointers can be changed at runtime.\
328308[thumbnail|upright 1.5](/wiki-images/a/a9/Linedemo-customdrawnpointer.png)
329309
330310Page **OnCustomdrawn pointer** demonstrates how a bitmap can be used as a data pointer, and how only every n-th pointer can be drawn. This is done by means of the event `OnCustomDrawPointer`.\
331311[thumbnail|upright 1.5](/wiki-images/4/4c/Linedemo-ongetpointerstyle.png)
332312
333313Using the event `OnGetPointerStyle` the pointers of individual data points of a line series can be changed. This is demonstrated on page **OnGetPointerStyle**..\
334314[thumbnail|upright 1.5](/wiki-images/d/d3/Linedemo-oscilloscope.png)
335315
336316Page **Oscilloscope**: Driven by a timer, more and more data points are added to the line series. The oldest data point is deleted once the series contains more than 20 points. The series is updated continously and is drawn using `LineType=ltStepXY`. The `OnTimer` event handler of the timer contains code to allow zooming into various parts of the chart while preserving the "oscilloscope" behavior.\
337317[thumbnail|upright 1.5](/wiki-images/9/92/Linedemo-coloreach.png)
338318
339319Page **Color each data point** applies the lineseries property `ColorEach` for colorizing individual datapoints and/or the adjacent line segments. The color is passed as the 4th parameter of the series method `AddXY(x, y, text, color)`.\
340320
341321### listbox
342322
343323[thumbnail|upright 1.5](/wiki-images/4/4a/Listboxdemo.png) `TChartListbox` is a useful add-on to TAChart for interactively turning selected series on and off. Just add a `TChartListbox` to the form and link its `Chart` property to the chart of interest. The project `listboxdemo` demonstrates that there is a two-way communication between chart and listbox: when listbox items are checked/unchecked the corresponding series are shown/hidden. Conversely, when series are added/deleted/shown/hidden in the chart the changes are reflected in the listbox automatically.\
344324
345325### liveview, liveview-paned
346326
347327[thumb|upright 1.0](/wiki-images/7/7e/Liveview.png) [thumb|upright 1.0](/wiki-images/9/91/Liveview-paned.png) These two projects demonstrate usage of the `TChartLiveView` component which displays, in a scrolling viewport, only the most recent data points arriving from some external source.
348328
349329In order to apply a `TChartLiveView` set its `Chart` property to the chart to be controlled. Set `Active` to `true` to activate the live view. Property `ViewportSize` determines the width of the scrolling window in axis units.
350330
351331While the `liveview` project applies to a normal chart with a single y axis, usage of several y axes is demonstrated in the `liveview-paned` project. The creation of a "paned chart" with several axes is the subject of the demo panes.\
352332
353333### multi
354334
355335[thumbnail|upright 1.5](/wiki-images/9/94/Multidemo-bubble.png) Usage of series with multiple y values is the subject of project **`multidemo`**. `TListChartSource` provides storage for additional y values in the array `YList[]`.
356336
357337See [[TAChart documentation]] of more details.
358338
359339Page **Bubble** shows a chart with a [[TAChart documentation|bubble series]]. This series draws data points as circles of variable radius centered at the data points. In addition to the standard `x`/`y` coordinates there must be a second y value to specify the radius. Since - as usual - a color value can be assigned to a data point bubble charts can show four-dimensional data.\
360340[thumbnail|upright 1.5](/wiki-images/4/48/Multidemo-stacked.png) Page **Stacked** shows stacked area, bar, or line series charts. Stacked series must provide a y value for the each stack levels. The `TChartStyles` component is used to define the color of the stacks.
361341
362342> **Note:** A detailed description how to create stacked charts is given in the tutorial [[TAChart Tutorial: Stacked BarSeries|"Stacked bar series"]].
363343
364-\
365344[thumbnail|upright 1.5](/wiki-images/7/76/Multidemo-boxwhisker.png) A chart with a [[TAChart documentation|Box-and-Whiskers-Series]] is displayed in page **Box-and-Whiskers**. This series type represents data as rectangles ("box") with a medium line and two T-shaped protrusions in both directions ("whiskers") . It requires five y values:
366345
367346- Lower whisker
368347- Lower box edge
369348- Medium line
370349- Upper box edge
371350- Upper whisker
372351
373-\
374352[thumbnail|upright 1.5](/wiki-images/2/29/Multidemo-ohlc.png) Page **OHLC** shows a chart with a [[TAChart documentation|Open-high-low-close series]] which represents data as a vertical lines with two ticks and requires four y values:
375353
376354- Lower point of line = "Low" value
377355- Left-facing tick position = "Open" value
378356- Right-facing tick position = "Close" value
379357- Upper point of line = "High" value
380358
381-\
382359[thumbnail|upright 1.5](/wiki-images/9/96/Multidemo-field.png) A simple [[TAChart documentation|field plot]] is demonstrated on page **Field**. This series type draws short arrows at the data points to highlight the directions of a vector field. It requires two x and two y values per data point.\
383360
384361### nan
385362
386363[thumbnail|upright 1.5](/wiki-images/e/e5/Nandemo.png) The project **`nandemo`** shows how values can be skipped from a series. Click on an x value in the checklistbox at the right to replace the x or y value of the corresponding data point by NaN. In a line series, a NaN value introduces a break in the originally continuous curve. In other series types, the effect is similar. See [[TAChart documentation]] of more details.\
387364
388365### navigate
389366
390367[thumbnail|upright 1.5](/wiki-images/0/0b/Navigatedemo.png) For navigation in a zoomed chart, TAChart provides the components [[TAChart documentation|TChartNavScrollbar]] and [[TAChart documentation|TChartNavPanel]]. Usage of these components is demonstarted in the **`navigatedemo`** project.
391368
392369The chart in which the navigation occurs must be assigned to this corresponding property. Note the property `MiniMap` which displays a reduced view of the chart and draws the current viewport as a highlighted rectangle.\
393370
394371### nogui
395372
396373[thumbnail|upright 1.5](/wiki-images/c/c2/Noguidemo.png) **`noguidemo`** demonstrates that TAChart can also be used for creating graphics output from console (no-gui) programs. This project creates a chart and a simple bar series at runtime and stores the output to a png file without a user-interface showing up.
397374
398375Note that, for Windows, the `freetype-6.dll` and `zlib1.dll` are required in the exe folder in order to run the demo.\
399376
400377### opengl
401378
402379[thumbnail|upright 1.5](/wiki-images/a/ac/Opengldemo.png) **`opengldemo`** presents code how to use OpenGL for improved rendering quality of the chart by means of `TOpenGLDrawer`. See [[TAChart documentation]] for details on this drawer. In addition, the demo illustrates also the usage of [[TAChart documentation|series transparency]].
403380
404381Note that the package `LazOpenGLContext` needs to be installed to compile this demo.\
405382
406383### panes
407384
408385[thumbnail|upright 1.5](/wiki-images/d/df/Panesdemo.png) When working with multiple charts in the same window it sometimes required to use common axes. The **`panes`** demo projects shows two possibilities how to achieve this:
409386
410387In page **Link** there are three charts, each with one series. The axes of the charts are linked by means of a `TChartExtentLink` component. The axes to be coupled are specified by the `Mode` property. Zoom in one of the chart by dragging a zoom rectangle with the left mouse button, and the other charts will follow.
411388
412389In page **Transform** there is only one chart, but with three series. Each series covers a third of the vertical chart area with its individual y axis. This effect can be achieved by means of three vertical axes and three [[TAChart documentation|AutoScaleAxisTransforms]].
413390
414391> **Note:** Step-by-step instructions are given in the tutorial "[[TAChart Tutorial: Multiple Panes in one Chart|Multiple panes in the same chart]]".
415392
416-\
417-
418393### print
419394
420395[thumbnail|upright 1.5](/wiki-images/f/f8/Printdemo.png) **`printdemo`** illustrates two ways of printing charts:
421396
422397- using direct painting on the printer's canvas by clicking on button "Print via canvas",
423398
424399``` pascal
425400Chart1.PaintOnCanvas(Printer.Canvas, ARect)
426401```
427402
428403- or using a dedicated drawer for printing (by clicking on button "Print") which generally yields better quality. Package `TAChartPrint` is necessary to use `TPrinterDrawer`. See [[TAChart documentation]] for details on [[TAChart documentation|TPrinterDrawer]].
429404
430405``` pascal
431406Chart1.Draw(TPrinterDrawer.Create(Printer), ARect);
432407```
433408
434409In general, printer support requires the package `Printer4Lazarus`. The demo also shows how axis marks can be highlighted by a border (`Chart1.LeftAxis.Marks.Frame.Visible := true`).\
435410
436411### radial
437412
438413[thumbnail|upright 1.5](/wiki-images/8/86/Radialdemo_pie.png) The **`radialdemo`** project introduces two series, the [[TAChart documentation|TPieSeries]] and the [[TAChart documentation|TPolarSeries]]. Both interpret the x/y coordinates as angle and distance from center, but in an opposite way.
439414
440415`TPieSeries` shown on page **Pie** assumes that the y value of the chart source is the angle of the pie, and the x coordinate corresponds to the distance of the slice from the center. Therefore, the effect of the "exploded" slice can be achieved by increasing the x value (if property `Exploded` is set). In addition, the demo allows to play with some properties of the pie series:
441416
442417- `MarkPositions`
443418- `RotateLabels`
444419- `Marks.LabelFont.Rotation`
445420
446421See section [[TAChart documentation|Pie series]] in the [[TAChart documentation|documentation]].\
447422[thumbnail|upright 1.5](/wiki-images/a/a7/Radialdemo_polar.png) The second page **Polar** shows two polar series. In a polar series, the x value is interpreted as the angle in radians, and the y value corresponds to the distance of the point from the center.
448423
449424Both series are linked to the same ChartSource. They are offset with respect to each other because the properties `OriginX` and `OriginY` are different. The checkbox "Closed" allows to close the polygons (property `CloseCircle`) by connecting the first data point with the last one.
450425
451426See section [[TAChart documentation|Polar series]] in the [[TAChart documentation|documentation]].\
452427
453428### rotate
454429
455430[thumbnail|upright 1.5](/wiki-images/c/cc/Rotatedemo.png) "Rotate" in the context of project **`rotatedemo`** means "rotation of a series with respect to the x and y axes", i.e. painting of a series with x and y axes interchanged.
456431
457432The demo starts with a line series, a bar series and a 3d area series in the regular arrangement of x along the horizontal and y along the vertical axis. After checking the checkbox assigned to a series, its x values are drawn along the vertical and the y values along the horizontal axes. In the rotated configuration the bars of a bar series are drawn horizontally.
458433
459434In TAChart, this kind of rotation is achieved by assigning the property `AxisIndexX` to the index of the vertical axis, and `AxisIndexY` to that of the horizontal axis.
460435
461436In addition to rotation, the demo project allows also to play with the position of the series marks by changing the property `MarkPositions` of the red dotted line series.\
462437
463438### save
464439
465440[thumbnail|upright 1.5](/wiki-images/d/da/Savedemo.png) The project **`savedemo`** shows code how to save a chart to an external graphics file (.bmp, .png, .jpg, .svg)
466441
467442``` pascal
468443Chart1.SaveToBitmapFile('test.bmp');
469444```
470445
471446or to copy it to the clipboard
472447
473448``` pascal
474449Chart1.CopyToClipboardBitmap;
475450```
476451
477-\
478-
479452### script
480453
481454[thumbnail|upright 1.5](/wiki-images/f/f3/Scriptdemo.png) The project **`scriptdemo`** applies [[Pascal Script|PascalScript]] to define the mathematical function shown in a [[TAChart documentation|TFuncSeries]]. In this way a mathematical function plotter can be created.
482455
483456A tutorial on usage of TFuncSeries can be found [[TAChart Tutorial: Function Series|here]].\
484457
485458### tools
486459
487460[thumbnail|upright 1.5](/wiki-images/e/ea/Toolsdemo.png) Project **`toolsdemo`** gives the opportunity to play with TAChart's zooming and panning tools. Follow the instructions on the screen to activate the individual tools.
488461
489462Internally, the work is done by the `TChartTool` components. Have a look at chapter [[TAChart documentation|Tools]] in the [[TAChart documentation]] or the tutorial "[[TAChart Tutorial: Chart Tools|Chart tools]]" to learn details on this powerful add-on to TAChart.\
490463
491464### wmf
492465
493466[thumbnail|upright 1.5](/wiki-images/b/bc/Wmfdemo.png) **`wmfdemo`** saves a chart to a windows metafile (.wmf):
494467
495468``` pascal
496469with Chart1 do
497470 Draw(TWindowsMetafileDrawer.Create('test.wmf'), Rect(0, 0, Width, Height));
498471
499472// or, after r46404:
500473Chart1.SaveToWMF('test.wmf');
501474```
502475
503476Since r46396, a chart can be **copied to the clipboard** as a windows metafile (windows-only); use an empty file name string in above `Draw` code for this purpose. After r46404, the simpler `Chart1.CopyToClipboardMetafile` has the same effect.
504477
505478> **Note:** wmf support in TAChart is very limited. In particular, it is available only on the Windows platform. Package `TAChartWMF` is required to compile this demo.
506-
507-\
508479
509480## Related documents
510481
511482**Main documentation:**
512483
513484- [[TAChart documentation]]
514485
515486**Tutorials:**
516487
517488- [[TAChart Tutorial: Getting started|Getting started]]
518489- [[TAChart Tutorial: BarSeries|Bar series]]
519490- [[TAChart Tutorial: Stacked BarSeries|Stacked bar series]]
520491- [[TAChart Tutorial: ListChartSource, Logarithmic Axis, Fitting|ListChartSource, logarithmic axis, fitting]]
521492- [[TAChart Tutorial: Userdefined ChartSource|User-defined ChartSource]]
522493- [[TAChart Tutorial: Dual y axis, Legend|Dual y axis, legend]]
523494- [[TAChart Tutorial: Chart Tools|Chart tools]]
524495- [[TAChart Tutorial: Function Series|Function series]]
525496- [[TAChart Tutorial: ColorMapSeries, Zooming|ColorMapSeries, zooming]]
526497- [[TAChart Tutorial: Multiple Panes in one Chart|Multiple panes in the same chart]]
527498- [[TAChart Tutorial: Background design|Background design]]
528499- [[BGRABitmap tutorial TAChart]]
529500
530501---
531502*From the Free Pascal wiki, page "TAChart Demos", as it stood on 2021-08-09 after a change by Wp, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
532503Category: Components
533504Category: Lazarus
534505Category: TAChart

Back to history