Series Coding
Series
A Line or Bar Chart can contain up to maximum of 12 series, a Pie Chart has only the series 1. The individual series can be address using the same syntax as used with arrays (e.g. series[1] for series 1). The series number can either be a literal value or a variable. When literal values are used a check will be made if it not exceeds the number of series defined with the Series Editor.
The series can then be changed using one of three functions or three properties shown in the sections below. The full syntax of such a command is
<ChartObject>.Series[<Number>].<Function or Property>
Where:
<ChartObject>: the name of the chart object in the layout
<Number>: either a fixed number or a variable.
<Function or Property>: one of the functions or properties shown below.
Short examples:
chart.series[2].color := clMaroon
Functions
ADD
The ADD function behaves differently for a Pie Chart than for a Line or Bar Chart so there are two descriptions below.
Pie Chart
Syntax:
ADD(<Weight>, <Color>, <Legend>)
Description:
Adds a part to the Pie Chart. When the chart is generated all the weights in the series will be added and the resulting total value will be used as 100% of the pie. All the weights will then be normalized to this total value.
Note: The color and legend values are mandatory.
Parameters:
<Weight>: The weight of the part in the pie.
<Color>: The color to use for this part of the pie.
<Legend>: The legend text for this part in the pie. This legend will only be shown when the chart property Legend is set to true. When the chart property ChartMark is set to a value to include label texts, this value will also be used for the label text.
Line or Bar Chart
Syntax:
ADD(<Value>[, <Label>])
Description:
Adds a datapoint to the series. When using this on an empty series the datapoint will be added with the X value set in the property StartOnXAxis of the series which defaults to zero. When adding additional datapoints the X value will be incremented with the value set in the chart property StepSize which defaults to 1.
Parameters:
<Value>: The Y value of the datapoint to add to the series.
<Label>: An optional label text to show with the datapoint. This label text will only be shown when the chart property ChartMark is set to a value that includes the label text.
ADDXY
Syntax:
ADDXY(<XValue>, <YValue>[, <Label>])
Description:
Adds a datapoint to the series at the X, Y coordinate specified in <XValue>, <YValue>. When using this function in a 3D Line chart the datapoints should be added with the X value ordered ascending or descending. In a 2D line chart the line will be drawn from the previous datapoint to the datapoint added making it possible to draw any figure.
Note: The ADDXY function cannot be used in a Pie Chart.
Parameters:
<XValue>: The X value of the datapoint to add to the series.
<YValue>: The Y value of the datapoint to add to the series.
<Label>: An optional label text to show with the datapoint.
This label text will only be shown when the chart property ChartMark is
set to a value that includes the label text.
CLEAR
Syntax:
CLEAR()
Description:
Deletes all the datapoints of the series.
Properties
COLOR
Access: Read/Write
Type: Integer
Description: Sets the color to use for the series. The color value should be added as hexadecimal value in the order BGR (e.g. $2299EE).
LEGEND
Access: Read/Write
Type: String
Description: Sets the legend text for the series. This legend text will only be shown when the chart property Legend is set to True.
STARTONXAXIS
Access: Read/Write
Type: Integer
Description: Sets the StartOnXAxis value to use for this series in Line or Bar Charts. This value has no significance in a Pie Chart.
Dynamically setting Chart Properties
The major number of Chart Properties can only be altered from the values set in the Object Inspector or Series Editor before the chart is drawn for the first time. I.e. in Display Main. |
Code Examples
Example for a Pie Chart
pie.series[1].add (100, $004080, 'Second')
pie.series[1].add (50, clred, 'Third')
pie.series[1].add (25, $0080FF, 'Fourth Part')
pie.series[1].add (12, clyellow, 'Fifth')
pie.series[1].add (6, clgreen, 'Sixth part')
Example for a Line or Bar Chart
chart.top := 25
chart.color := clYellow
chart.fontbold := true
chart.fontcolor := clBlue
chart.fontitalic := true
chart.fontname := 'Segoe Print'
chart.fontsize := 24
chart.fontunderline := true
chart.helptext := 'Some nice helptext for this chart!!!'
chart.max_x_value := 7
chart.max_y_value := 32000
chart.min_x_value := -1
chart.min_y_value := -2000
chart.series[1].add(0)
chart.series[1].add(5000)
chart.series[1].add(20000)
chart.series[1].add(25000)
chart.series[1].add(23000)
loop for i := 0 to 4
chart.series[2].add(i ** 2 * 1750)
endloop
chart.series[1].color := clLime
chart.series[2].color := clMaroon
chart.series[1].legend := 'Lime'
chart.series[2].legend := 'Maroon'
chart.series[1].startonxaxis := -1
chart.series[2].startonxaxis := -1
chart.set_x_axis_to_zero := true
chart.set_y_axis_to_zero := true
chart.stepsize := 2
chart.stepsize_x := 1
chart.stepsize_y := 2000
chart.visible := true
chart.xlabels[1] := 'One'
chart.xlabels[2] := 'Two'
chart.xlabels[3] := 'Three'
chart.xlabels[4] := 'Four'
chart.xlabels[5] := 'Five'
Example of the usage of ADDXY in a Line Chart
loop for i := 0 to 5
line.series[1].addxy(i * 10, i ** 2, format(i))
endloop
loop for i := 0 to 4
lblnr := i + 6
line.series[1].addxy(43 - i * 10, 6 * (4 - i), format(lblnr))
endloop
loop for i:= 0 to 3
lblnr := i + 11
line.series[1].addxy(7 + i * 10, - 10 - i, format(lblnr))
endloop