Annotation Macros

Annotation macros are predefined variables used to dynamically position individual annotation items. Macros assume values at run-time and can be used with all annotation positioning attributes to position annotations relative to chart/gauge elements, like the caption, legend, and so on. For example, for an annotation item, if you set "x": "$captionStartX"”", x will be assigned the value of the starting x coordinate of the chart caption.

You can use any number of macros as variables with the positioning attributes. Using the + or - operators, you can add or subtract the macro values from each other or from a fixed number. For example, for an annotation item, assume that you set "x": "$canvasStartX + $chartLeftMargin + 2". The starting x coordinate of the item will now be set to a value that is the starting x coordinate of the chart canvas, the chart’s left margin, and a fixed two pixels added to together.

You can use only the + or - operators to create a macro expression. There should be at least one macro name to create a macro expression. Common mathematical expressions like 30 + 10 - 5, which do not contain a macro, will not work.

When a chart or a gauge is resized, the values provided by macros are not scaled. Instead, they are replaced with the new values provided by the resized chart. However, the numeric values present in the macro expressions are scaled. For example, the value 10 in the expression $chartStartY + 10 is scaled when the chart is dynamically resized. To avoid this, prefix the number with the $ symbol. For example, the value 10 in the expression $chartStartY + $10 is NOT scaled when you dynamically resize the chart.

Dynamic Positioning using Macros

Annotations can be positioned dynamically with respect to the chart itself and chart elements like the legend, caption, canvas, axes, as well as the datasets.

Positioning Annotations with Respect to the Canvas

A spline chart configured to position annotations with respect to the chart canvas is shown below:

FusionCharts will load here..

In the chart above, the annotation items (a rectangle and a text label) showing the total footfall at Bakersfield Central are positioned at the top-right corner of the canvas. The values of the attributes x, y,toX, and toY are specified with respect to the canvas start and end position, using annotation macros.

Positioning Annotations with Respect to Datasets

A spline chart configured to position annotations with respect to datasets is shown below:

FusionCharts will load here..

In the chart above, the annotation items (the horizontal dashed line, a text label on a rectangle at extreme left of the dashed line, and the label with the store name and the total number of visitors on the extreme right side of the line) are dynamically positioned such that they appear when you hover the mouse pointer over the corresponding anchor. This is done by specifying values for the x, y,tox, and toy` attributes with respect to the dataset position, using annotation macros.

A brief description of the sub-token macros used to position annotations with respect to datasets is given below:

For example, to position a rectangle above the second column in a column chart, the possible values could be:
x: $dataset.0.set.1.STARTX,
y:$dataset.0.set.1.STARTY,
tox: $dataset.0.set.1.STARTX+100,
toy:$dataset.0.set.1.STARTY-40