Chart Custom Labels
Overview
AnyChart Stock allows to add labels to the given chart or all charts panel. These labels have special positioning mechanism and display only static text.
The scheme below shows an idea of these labels: we have a General area for all charts, and can place Labels to this area, and in this area we have several charts - each of them can also have labels.
The reason why we talk about both general and chart labels together is the fact that they are almost identical, the difference is only
in the place where they are configured and anchor points position. Please see samples and configuration options below.
Adding Common Labels
Common labels are labels for the General area described above, these labels are usually used to describe all charts, set copyright or source info, and other. You can place them according to anchor and tune the position with x_padding and y_padding.
Here is a sample XML that demonstrates using common labels:
01 |
<?xml version="1.0" encoding="UTF-8"?> |
02 |
< stock xmlns = "http://anychart.com/products/stock/schemas/1.9.0/schema.xsd" > |
This live sample shows how it works:
Live Sample: Common Labels
Adding Labels to the chart
You can also define labels directly to the chart by using labels subnode of chart node — sample XML below shows how to define labels to specific chart:
01 |
<?xml version="1.0" encoding="UTF-8"?> |
02 |
< stock xmlns = "http://anychart.com/products/stock/schemas/1.9.0/schema.xsd" > |
12 | format: "Chart1 label text" |
24 | format: "Chart 2 label text" |
This live sample demonstrates charts with labels defined specifically:
Live Sample: Individual Chart Labels
Positioning
Any label has its own positioning settings and is anchored to one of the anchor points.
These are the attributes of the <label> node are used for defining label position:
Attribute |
Possible Values |
Description |
anchor |
LeftTop
RightTop
LeftBottom
RightBottom
LeftCenter
RightCenter
TopCenter
BottomCenter
Center |
Sets label anchor. |
x_padding |
Any number |
Sets label X padding |
y_padding |
Any number |
Sets label Y padding |
The anchor attribute sets anchor point. Look at this illustration below that explain the idea of anchor points.
These are anchor points of General Area, described in overview, these anchors are valid for Common labels:
These are anchor points for each chart - Chart custom labels are placed according to these anchors:
Here is a sample XML that demonstrates adding a label to the chart:
This live sample demonstrates a chart with two labels:
Live Sample: Positioning Individual Chart Labels
Configuring labels
AnyChart Stock provides rich capabilities of label customization, its text and background settings. In this section you can find samples of various XML attributes and its values on Common labels example, but all the same options are available for specific chart labels.
Text
To define a label text, use the <format> node. Use the CDATA block to enable using special characters or skip it otherwise. The CDATA block allows allows adding multi line texts.
Here is a sample XML that shows how to define a label text:
Font
The font settings are configured in the typical <font> node. Here is a sample XML that demonstrates customizing the font settings:
This live sample demonstrates the customized text:
Live Sample: Individual Chart Labels Font Settings
Find out more about font settings in Font Settings and XML Reference.
Background
Like the majority of other text elements, labels too can have a background. By default, the background is turned off, but you can turn it on and customize.
Here is a sample XML that demonstrates customizing background settings:
This live sample demonstrates labels with background:
Live Sample: Individual Chart Labels Background Settings
Find out more about background settings in Background Settings and XML Reference.