Data labels in JavaScript Chart control

18 Nov 20183 minutes to read

Data labels display the values of data points directly on the chart, reducing the need to reference axes for exact values. Enable data labels by setting the visible option to true in the dataLabel configuration. Labels automatically adjust to avoid overlapping and maintain readability.

Note: To use the data label feature, inject DataLabel using Chart.Inject(DataLabel) method.

Position

Use the position property to place data labels at Top, Middle, Bottom, or Outer (applicable to column and bar series). Appropriate label positioning enhances clarity and preserves chart readability.

Note: The Outer position applies only to column and bar series types.

Data Label Template

Customize label content using templates. Use placeholders such as ${point.x} and ${point.y} to display data point values. The template property enables fully customizable and visually rich labels.

Text Mapping

Display custom text using the name property, which maps label text from a specific field in the data source. This feature is useful for descriptive or category‑based labels.

Format

Apply number or date formatting using the format property. Global formatting symbols include:

  • n – number format
  • p – percentage format
  • c – currency format
Value Format Resultant Value Description
1000 n1 1000.0 Rounded to 1 decimal place.
1000 n2 1000.00 Rounded to 2 decimal places.
1000 n3 1000.000 Rounded to 3 decimal places.
0.01 p1 1.0% Converted to percentage with 1 decimal place.
0.01 p2 1.00% Converted to percentage with 2 decimal places.
0.01 p3 1.000% Converted to percentage with 3 decimal places.
1000 c1 $1000.0 Currency with 1 decimal place.
1000 c2 $1000.00 Currency with 2 decimal places.

Margin

Adjust spacing around labels using the margin property, which includes left, right, bottom, and top values. Margins help prevent labels from overlapping chart elements.

Customization

Enhance label appearance using properties such as fill (background), border, and corner radius (rx, ry). Refine text appearance using the font settings, which support color, fontFamily, fontWeight, and size.

Note: The rx and ry properties require non‑null border values.

Customizing Specific Point

Customize individual markers or labels using the pointRender and textRender events.

  • pointRender modifies shape, color, or border of a point.
  • textRender customizes the label text for specific points.

Show percentage based on each series points

Calculate and display percentage values based on each series’ total using the seriesRender and textRender events.

  • In seriesRender, compute the total of y values.
  • In textRender, calculate the percentage for each point and update the label text.

Last value label

The lastValueLabel feature highlights the final data point in a series, making the latest trend or value easy to identify.

Enable last value label

Enable the label by setting the enable property inside the lastValueLabel configuration.

Note: To use the last value label feature, inject the LastValueLabel module using Chart.Inject(LastValueLabel) method.

Customization

Customize the appearance using properties such as font, background, border, dashArray, lineWidth, lineColor, rx, and ry.

See Also