TAChart Tutorial: BarSeries

From Free Pascal wiki
Revision as of 11:02, 28 February 2014 by Wp (talk | contribs) (Created page with "--- WORK IN PROGRESS --- ----- NOT FINISHED ----- == Introduction == So, let's get started. == Preparation == === Setting up the chart === Create a new project, save it. ...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

--- WORK IN PROGRESS ---


NOT FINISHED -----

Introduction

So, let's get started.

Preparation

Setting up the chart

Create a new project, save it. Add a TChart component from Lazarus' component palette to Form1, client-align it to fill the entire form.

Adding series

Suppose we want to have three bar series in the chart. Therefore, double-click on the chart to open the series editor. Click "Add" and select "Bar series" from the list. Repeat two time. Now we have three bar series in the chart. We don't see them in the chart since they do not yet contain any data. In the object tree of the object inspector, however, the series appear as children of the TChart entry.

Before adding data rename the first bar series to "RedBarSeries" and set its property SeriesColor to clRed. Similarly, adjust the other series which will be called "BlueBarSeries" and "YellowBarSeries" and have a SeriesColor of clBlue and clYellow, respectively. It is always a good idea to use "speaking" names for the components.

Data for plotting

Before continueing let's think about which data we want to plot. Maybe you could use the balance of your checking and saving account, or the business results of large companies found somewhere in the internet. Let's go a different way this time: why don't we plot random data? Of course, they don't mean anything, but they are simple and a great tool for exercising. And in particular, TAChart contains the TRandomChartSource component which provides random data to be plugged into a series seamlessly at design-time. This means you can follow this tutorial without a need to write a line of code and without a need to compile the demo application.

Since we have three series we need three chart sources as well.

ComponentPalette RandomChartSource.png