Axis labels in TypeScript Charts

This guide demonstrates how to configure and customize axis labels in Syncfusion JavaScript Charts, including label positioning, overlap handling, multi-level labels, and advanced formatting options.

Smart axis labels

When axis labels overlap due to limited space or dense data points, the labelIntersectAction property can be used to control how the labels are rendered. This helps improve readability by automatically adjusting label visibility or orientation. The supported values are None, Hide, Rotate45, Rotate90, Rotate45WithTrim, Rotate90WithTrim, Wrap, MultipleRows, and Trim. The default value is None.

Label Handling Options:

  • None: No action (displays all labels as-is)
  • Hide: Hides overlapping labels for clarity
  • Rotate45: Rotates labels 45 degrees
  • Rotate90: Rotates labels vertically (90 degrees)
  • Rotate45WithTrim: Rotates 45 degrees and trims long text
  • Rotate90WithTrim: Rotates vertically and trims long text
  • Wrap: Wraps text to multiple lines
  • MultipleRows: Distributes labels across multiple rows
  • Trim: Truncates text without rotation

When setting labelIntersectAction as Hide, overlapping labels are hidden to avoid visual clutter.

import { Chart, Category, ColumnSeries, LineSeries } from '@syncfusion/ej2-charts';
Chart.Inject(ColumnSeries, Category, LineSeries);
let chartData: Object[] = [{ x: "South Korea", y: 39.4 }, { x: "India", y: 61.3 }, { x: "Pakistan", y: 20.4 },
    { x: "Germany", y: 65.1 }, { x: "Australia", y: 15.8 }, { x: "Italy", y: 29.2 },
    { x: "United Kingdom", y: 44.6 }, { x: "Saudi Arabia", y: 9.7 }, { x: "Russia", y: 40.8 },
    { x: "Mexico", y: 31 }, { x: "Brazil", y: 75.9 }, { x: "China", y: 51.4 }];
let chart: Chart = new Chart({
    primaryXAxis: {
        valueType: 'Category',
        //label intersect as hide
        labelIntersectAction: 'Hide'
    },
   series:[{
        dataSource: chartData,
        xName: 'x', yName: 'y',
        type: 'Column'
    }],

}, '#element');
<!DOCTYPE html>
<html lang="en">

<head>
    <title>EJ2 Animation</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript UI Controls" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <div id='container'>
        <div id='element'></div>
    </div>
</body>

</html>

When setting labelIntersectAction as Rotate45, the labels are rotated by 45 degrees to reduce overlap.

import { Chart, Category, ColumnSeries, LineSeries } from '@syncfusion/ej2-charts';
import { smartAxisData } from './datasource.ts';
Chart.Inject(ColumnSeries, Category, LineSeries);

let chart: Chart = new Chart({
    primaryXAxis: {
        valueType: 'Category',
        // label intersect as 45
        labelIntersectAction: 'Rotate45'
    },
   series:[{
        dataSource: smartAxisData,
        xName: 'x', yName: 'y',
        type: 'Column'
    }],

}, '#element');
<!DOCTYPE html>
<html lang="en">

<head>
    <title>EJ2 Animation</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript UI Controls" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <div id='container'>
        <div id='element'></div>
    </div>
</body>

</html>

When setting labelIntersectAction as Rotate90, the labels are rotated vertically to maximize space utilization.

import { Chart, Category, ColumnSeries, LineSeries } from '@syncfusion/ej2-charts';
import { smartAxisData } from './datasource.ts';
Chart.Inject(ColumnSeries, Category, LineSeries);

let chart: Chart = new Chart({
    primaryXAxis: {
        valueType: 'Category',
        // label intersect as 90
        labelIntersectAction: 'Rotate90'
    },
    series:[{
        dataSource: smartAxisData,
        xName: 'x', yName: 'y',
        type: 'Column'
    }],

}, '#element');
<!DOCTYPE html>
<html lang="en">

<head>
    <title>EJ2 Animation</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript UI Controls" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <div id='container'>
        <div id='element'></div>
    </div>
</body>

</html>

When setting labelIntersectAction as Rotate45WithTrim, the labels are trimmed when the available space is insufficient and rotated by 45 degrees.

import { Chart, Category, ColumnSeries, LineSeries } from '@syncfusion/ej2-charts';
import { smartAxisData } from './datasource.ts';
Chart.Inject(ColumnSeries, Category, LineSeries);

let chart: Chart = new Chart({
    primaryXAxis: {
        title: 'Countries',
        valueType: 'Category',
        // label intersect as 45
        labelIntersectAction: 'Rotate45WithTrim'
    },
    primaryYAxis: {
        minimum: 0, maximum: 80, interval: 10,
        title: 'People(in millions)'
    },
    axes:[
        {
            majorGridLines: { width: 0 },
            rowIndex: 0, opposedPosition: true,
            lineStyle: { width: 0 },
            minimum: 24, maximum: 36, interval: 2,
            name: 'yAxis', title: 'Temperature (Celsius)',
            labelFormat: '{value}°C'
        }
    ],
    series:[{
        dataSource: smartAxisData,
        xName: 'x', yName: 'y',
        name: 'Internet', type: 'Column'
    }],
    title: 'Internet Users'
}, '#element');
<!DOCTYPE html>
<html lang="en">

<head>
    <title>EJ2 Chart - Smart Axis Label</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript UI Controls" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <div id='container'>
        <div id='element'></div>
    </div>
</body>

</html>

When setting labelIntersectAction as Rotate90WithTrim, the labels are trimmed when the available space is insufficient and rotated vertically.

import { Chart, Category, ColumnSeries, LineSeries } from '@syncfusion/ej2-charts';
import { smartAxisData } from './datasource.ts';
Chart.Inject(ColumnSeries, Category, LineSeries);

let chart: Chart = new Chart({
    primaryXAxis: {
        title: 'Countries',
        valueType: 'Category',
        // label intersect as 90
        labelIntersectAction: 'Rotate90WithTrim'
    },
    primaryYAxis: {
        minimum: 0, maximum: 80, interval: 10,
        title: 'People(in millions)'
    },
    axes:[
        {
            majorGridLines: { width: 0 },
            rowIndex: 0, opposedPosition: true,
            lineStyle: { width: 0 },
            minimum: 24, maximum: 36, interval: 2,
            name: 'yAxis', title: 'Temperature (Celsius)',
            labelFormat: '{value}°C'
        }
    ],
    series:[{
        dataSource: smartAxisData,
        xName: 'x', yName: 'y',
        name: 'Internet', type: 'Column'
    }],
    title: 'Internet Users'
}, '#element');
<!DOCTYPE html>
<html lang="en">

<head>
    <title>EJ2 Chart - Smart Axis Label</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript UI Controls" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <div id='container'>
        <div id='element'></div>
    </div>
</body>

</html>

Axis label positioning

By default, axis labels are positioned Outside the axis line using the labelPosition property. Labels can also be placed Inside the axis line, which is useful when optimizing space within the chart area. Supported values are Inside and Outside (default: Outside).

import { Chart, ColumnSeries, Category } from '@syncfusion/ej2-charts';
import { categoryData } from './datasource.ts';
Chart.Inject(ColumnSeries, Category);

let chart: Chart = new Chart({
    primaryXAxis: {
        valueType: 'Category',
        // label position as inside
        labelPosition: 'Inside',
    },
    series:[{
        dataSource: categoryData,
        xName: 'country', yName: 'gold',
        type: 'Column'
    }],

}, '#element');
<!DOCTYPE html>
<html lang="en">

<head>
    <title>EJ2 Animation</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript UI Controls" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <div id='container'>
        <div id='element'></div>
    </div>
</body>

</html>

Multilevel labels

Multiple levels of labels can be displayed on an axis using the multiLevelLabels property. This feature is useful for grouping related categories and improving data interpretation. Each multilevel label level can be independently configured with the following options:

• Categories: Define the range and content of multilevel labels
• Overflow: Control text overflow behavior (trim or wrap)
• Alignment: Position labels relative to the axis
• Text style: Customize font, color, and text properties
• Border: Customize border appearance around label groups

Note: To use the multilevel label feature, inject MultiLevelLabel using Chart.Inject(MultiLevelLabel) method before creating the chart instance.

Categories

Using the categories property, the start, end, text, and maximumTextWidth values of multilevel labels can be configured to define the label range and content.

import {
    Chart,
    ColumnSeries,
    Category,
    MultiLevelLabel
} from '@syncfusion/ej2-charts';

Chart.Inject(ColumnSeries, Category, MultiLevelLabel);

let chart: Chart = new Chart({
    primaryXAxis: {
        valueType: 'Category',
        // Multilevel labels with categories
        multiLevelLabels: [{
            categories: [
                { start: 0, end: 2, text: 'Q1-Q3 2014-2015', maximumTextWidth: 50 },
                { start: 3, end: 5, text: 'Q4 2015-Q2 2017', maximumTextWidth: 50 },
                { start: 6, end: 7, text: 'Q3-Q4 2020-2021', maximumTextWidth: 50 }
            ]
        }],
        title: 'Year'
    },
    primaryYAxis: {
        minimum: 0,
        maximum: 50,
        interval: 10,
        title: 'Sales in Percentage'
    },
    series: [{
        dataSource: [
            { x: '2014', y: 21.5 },
            { x: '2015', y: 24 },
            { x: '2016', y: 36.5 },
            { x: '2017', y: 30.4 },
            { x: '2018', y: 29.3 },
            { x: '2019', y: 41.4 },
            { x: '2020', y: 35 },
            { x: '2021', y: 42.4 }
        ],
        xName: 'x',
        yName: 'y',
        name: 'Sales',
        type: 'Column'
    }],
    title: 'Multilevel Labels - Categories'
}, '#element');

chart.appendTo('#element');
<!DOCTYPE html>
<html lang="en">

<head>
    <title>EJ2 Animation</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript UI Controls" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <div id='container'>
        <div id='element'></div>
    </div>
</body>

</html>

Overflow

Using the overflow property, multilevel labels can be configured to either Trim or Wrap when the text exceeds the available space. Default value is Wrap.

import {
    Chart,
    ColumnSeries,
    Category,
    MultiLevelLabel
} from '@syncfusion/ej2-charts';

Chart.Inject(ColumnSeries, Category, MultiLevelLabel);

let chart: Chart = new Chart({
    primaryXAxis: {
        valueType: 'Category',
        // Multilevel labels with overflow wrap
        multiLevelLabels: [{
            overflow: 'Wrap',
            categories: [
                { start: 0, end: 2, text: 'Years from 2014 to 2016' },
                { start: 3, end: 5, text: 'Years from 2017 to 2019' },
                { start: 6, end: 7, text: 'Years from 2020 to 2021' }
            ]
        }],
        title: 'Year'
    },
    primaryYAxis: {
        minimum: 0,
        maximum: 50,
        interval: 10,
        title: 'Sales in Percentage'
    },
    series: [{
        dataSource: [
            { x: '2014', y: 21.5 },
            { x: '2015', y: 24 },
            { x: '2016', y: 36.5 },
            { x: '2017', y: 30.4 },
            { x: '2018', y: 29.3 },
            { x: '2019', y: 41.4 },
            { x: '2020', y: 35 },
            { x: '2021', y: 42.4 }
        ],
        xName: 'x',
        yName: 'y',
        name: 'Sales',
        type: 'Column'
    }],
    title: 'Multilevel Labels - Overflow Wrap'
}, '#element');

chart.appendTo('#element');
<!DOCTYPE html>
<html lang="en">

<head>
    <title>EJ2 Animation</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript UI Controls" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <div id='container'>
        <div id='element'></div>
    </div>
</body>

</html>

Alignment

The alignment property provides options to position multilevel labels at Far, Center, or Near relative to the axis. Default value is Center.

import {
    Chart,
    ColumnSeries,
    Category,
    MultiLevelLabel
} from '@syncfusion/ej2-charts';

Chart.Inject(ColumnSeries, Category, MultiLevelLabel);

let chart: Chart = new Chart({
    primaryXAxis: {
        valueType: 'Category',
        // Multilevel labels with alignment
        multiLevelLabels: [{
            alignment: 'Center',
            categories: [
                { start: 0, end: 2, text: '2014-2016' },
                { start: 3, end: 5, text: '2017-2019' },
                { start: 6, end: 7, text: '2020-2021' }
            ]
        }],
        title: 'Year'
    },
    primaryYAxis: {
        minimum: 0,
        maximum: 50,
        interval: 10,
        title: 'Sales in Percentage'
    },
    series: [{
        dataSource: [
            { x: '2014', y: 21.5 },
            { x: '2015', y: 24 },
            { x: '2016', y: 36.5 },
            { x: '2017', y: 30.4 },
            { x: '2018', y: 29.3 },
            { x: '2019', y: 41.4 },
            { x: '2020', y: 35 },
            { x: '2021', y: 42.4 }
        ],
        xName: 'x',
        yName: 'y',
        name: 'Sales',
        type: 'Column'
    }],
    title: 'Multilevel Labels - Alignment'
}, '#element');

chart.appendTo('#element');
<!DOCTYPE html>
<html lang="en">

<head>
    <title>EJ2 Animation</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript UI Controls" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <div id='container'>
        <div id='element'></div>
    </div>
</body>

</html>

Text customization

The textStyle property of multilevel labels provides options to customize the size, color, fontFamily, fontWeight, fontStyle, opacity, textAlignment, and textOverflow.

import {
    Chart,
    ColumnSeries,
    Category,
    MultiLevelLabel
} from '@syncfusion/ej2-charts';

Chart.Inject(ColumnSeries, Category, MultiLevelLabel);

let chart: Chart = new Chart({
    primaryXAxis: {
        valueType: 'Category',
        multiLevelLabels: [
            {
                categories: [
                    {
                        start: 0,
                        end: 2,
                        text: '2014-2016'
                    },
                    {
                        start: 3,
                        end: 5,
                        text: '2017-2019'
                    },
                    {
                        start: 6,
                        end: 7,
                        text: '2020-2021'
                    }
                ],
                textStyle: {
                    size: '14px',
                    color: '#1f77b4',
                    fontWeight: '600'
                }
            }
        ],
        title: 'Year'
    },
    primaryYAxis: {
        minimum: 0,
        maximum: 50,
        interval: 10,
        title: 'Sales in Percentage'
    },
    series: [
        {
            dataSource: [
                { x: '2014', y: 21.5 },
                { x: '2015', y: 24 },
                { x: '2016', y: 36.5 },
                { x: '2017', y: 30.4 },
                { x: '2018', y: 29.3 },
                { x: '2019', y: 41.4 },
                { x: '2020', y: 35 },
                { x: '2021', y: 42.4 }
            ],
            xName: 'x',
            yName: 'y',
            name: 'Sales',
            type: 'Column'
        }
    ],
    title: 'Multilevel Labels - Text Style'
});

chart.appendTo('#element');
<!DOCTYPE html>
<html lang="en">

<head>
    <title>EJ2 Animation</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript UI Controls" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <div id='container'>
        <div id='element'></div>
    </div>
</body>

</html>

Border customization

Using the border property, the width, color, and type of the multilevel label border can be customized. The supported border types are Rectangle, Brace, WithoutBorder, WithoutTopBorder, WithoutTopandBottomBorder, and CurlyBrace.

import { Chart, ColumnSeries, Category, MultiLevelLabel } from '@syncfusion/ej2-charts';
import { categoryData, MultiLevelLabel } from './datasource.ts';
Chart.Inject(ColumnSeries, Category, MultiLevelLabel);

let chart: Chart = new Chart({
    primaryXAxis: {
        valueType: 'Category',
           multiLevelLabels:[{
               categories: [{start: -0.5, end: 3.5, text: 'Half Yearly 1' },
                        { start: 3.5, end: 7.5, text: 'Half Yearly 2' }],
               border:{type:'Brace', color:'Blue', width: 2},
           }]
    },
    series:[{
        dataSource: categoryData,
        xName: 'country', yName: 'gold',
        type: 'Column'
    }],

}, '#element');
<!DOCTYPE html>
<html lang="en">

<head>
    <title>EJ2 Animation</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript UI Controls" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <div id='container'>
        <div id='element'></div>
    </div>
</body>

</html>

Edge label placement

Labels with long text at the edges of an axis may appear partially outside the chart area. To avoid this, use the edgeLabelPlacement property in the axis. By default, the property is set to Shift, ensuring that labels are repositioned inside the chart area to prevent overlap.

Supported values:

  • Shift: Moves edge labels inside the chart area (default)
  • Hide: Hides edge labels that extend outside the chart area
  • None: No action will be performed on edge labels.
import { Chart, ColumnSeries, Category } from '@syncfusion/ej2-charts';

Chart.Inject(ColumnSeries, Category);

let chart: Chart = new Chart({
    primaryXAxis: {
        valueType: 'Category',
        // Edge label placement to shift long labels
        edgeLabelPlacement: 'Shift',
        title: 'Products'
    },
    primaryYAxis: {
        minimum: 0,
        maximum: 800,
        interval: 100,
        title: 'Sales Values'
    },
    series: [{
        dataSource: [
            { x: 'Product A', y: 72 },
            { x: 'Product B', y: 103 },
            { x: 'Product C', y: 139 },
            { x: 'Product D - Very Long Label', y: 462 },
            { x: 'Product E - Extended Text', y: 721 },
            { x: 'Product F', y: 286 }
        ],
        xName: 'x',
        yName: 'y',
        name: 'Sales',
        type: 'Column'
    }],
    title: 'Edge Label Placement - Shift'
}, '#element');

chart.appendTo('#element');
<!DOCTYPE html>
<html lang="en">

<head>
    <title>EJ2 Animation</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript UI Controls" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <div id='container'>
        <div id='element'></div>
    </div>
</body>

</html>

Sorting

The chart data source can be sorted using the sort utility before it is assigned to the series. In this example, use the drop-down list to select the sorting mode:

  • Select X to sort the data by the x category field.
  • Select Y to sort the data by the car, trucks, bike, and cycle value fields.
  • Use the Descending option to control the sort order. When selected, the data is sorted in descending order; otherwise, it is sorted in ascending order.

After sorting, the updated data source is assigned to all the stacked column series, and the refresh method is called to render the chart with the updated order

import {
    Chart,
    StackingColumnSeries,
    Category,
    Legend,
    Tooltip,
    sort,
  } from '@syncfusion/ej2-charts';
  import { DropDownList } from '@syncfusion/ej2-dropdowns';
  Chart.Inject(StackingColumnSeries, Category, Legend, Tooltip);
  
  let dataValues: Object[] = [
    { x: 'Asia', car: 120, trucks: 90, bike: 180, cycle: 90 },
    { x: 'Canada', car: 100, trucks: 80, bike: 90, cycle: 80 },
    { x: 'Europe', car: 80, trucks: 90, bike: 60, cycle: 50 },
    { x: 'Africa', car: 40, trucks: 20, bike: 30, cycle: 30 },
    { x: 'Mexico', car: 40, trucks: 50, bike: 80, cycle: 50 },
    { x: 'US', car: 140, trucks: 90, bike: 75, cycle: 70 },
  ];
  let chart: Chart = new Chart({
    //Initializing Primary X Axis
    primaryXAxis: {
      majorGridLines: { width: 0 },
      minorGridLines: { width: 0 },
      majorTickLines: { width: 0 },
      minorTickLines: { width: 0 },
      interval: 1,
      lineStyle: { width: 0 },
      labelIntersectAction: 'Rotate45',
      valueType: 'Category',
    },
    //Initializing Primary Y Axis
    primaryYAxis: {
      title: 'Sales',
      lineStyle: { width: 0 },
      majorTickLines: { width: 0 },
      majorGridLines: { width: 1 },
      minorGridLines: { width: 1 },
      minorTickLines: { width: 0 },
      labelFormat: '{value}K',
    },
    chartArea: {
      border: {
        width: 0,
      },
    },
    //Initializing Chart Series
    series: [
      {
        type: 'StackingColumn',
        dataSource: dataValues,
        xName: 'x',
        width: 2,
        yName: 'car',
        name: 'Car',
      },
      {
        type: 'StackingColumn',
        dataSource: dataValues,
        xName: 'x',
        width: 2,
        yName: 'trucks',
        name: 'Trucks',
      },
      {
        type: 'StackingColumn',
        dataSource: dataValues,
        xName: 'x',
        width: 2,
        yName: 'bike',
        name: 'Bike',
      },
      {
        type: 'StackingColumn',
        dataSource: dataValues,
        xName: 'x',
        width: 2,
        yName: 'cycle',
        name: 'Cycle',
      },
    ],
    //Initializing Chart title
    title: 'Vehicle Sales by Region',
    //Initializing User Interaction Tooltip
    tooltip: {
      enable: true,
      enableHighlight: true,
    }
  });
  chart.appendTo('#element');
  let sortMode: DropDownList = new DropDownList({
    index: 0,
    placeholder: 'Select Range Bar Color',
    width: 120,
    change: () => {
      sortDataSource(sortMode.value + '');
    },
  });
  sortMode.appendTo('#sortMode');
  document.getElementById('decending').onchange = () => {
    sortDataSource(sortMode.value + '');
  };
  function sortDataSource(value: string): void {
    let element: HTMLInputElement = document.getElementById(
      'decending'
    ) as HTMLInputElement;
    let isDecending: boolean = element.checked;
    element.disabled = false;
    let sortData: Object[];
    if (value === 'X') {
      sortData = sort(dataValues, ['x'], isDecending);
    } else if (value === 'Y') {
      sortData = sort(
        dataValues,
        ['car', 'trucks', 'bike', 'cycle'],
        isDecending
      );
    } else {
      element.disabled = true;
      sortData = dataValues;
    }
    chart.series[0].animation.enable = false;
    chart.series[1].animation.enable = false;
    chart.series[2].animation.enable = false;
    chart.series[3].animation.enable = false;
    chart.series[0].dataSource = sortData;
    chart.series[1].dataSource = sortData;
    chart.series[2].dataSource = sortData;
    chart.series[3].dataSource = sortData;
    chart.refresh();
  }
<!DOCTYPE html>
<html lang="en">

<head>
    <title>EJ2 Animation</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript UI Controls" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <div id="container">
      <div class="stackblitz-container tailwind3">
        <div>
            <div class="col-md-8 control-section">
                <div class="content-wrapper">
                    <div id="element" style="width:92%"></div>
                </div>
            </div>
            <div class="col-md-4 property-section">
                <table id="property" title="Properties" style="width: 100%">
                    <tbody>
                        <tr style="height: 50px">
                            <td style="width: 60%">
                                <div id="checkValue">Descending:</div>
                            </td>
                            <td style="width: 40%;">
                                <div>
                                    <input id="decending" type="checkbox" disabled="" aria-labelledby="Checkbox unchecked">
                                </div>
                            </td>
                        </tr>
                        <tr style="height: 50px">
                            <td style="width: 60%">
                                <div>Sort By:</div>
                            </td>
                            <td style="width: 40%;">
                                <div>
                                    <select name="selectIndex" autocomplete="off" id="sortMode">
                                        <option value="None">None</option>
                                        <option value="X">Sort by X</option>
                                        <option value="Y">Sort by Y</option>
                                    </select>
                                </div>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</body>

</html>

Label customization

The labelStyle property of an axis provides options to customize the color, font-family, font-size, and font-weight of axis labels.

import { Chart, ColumnSeries, Category } from '@syncfusion/ej2-charts';

Chart.Inject(ColumnSeries, Category);

let chart: Chart = new Chart({
    primaryXAxis: {
        valueType: 'Category',
        // Customize label style
        labelStyle: {
            color: '#1f77b4',
            fontFamily: 'Arial',
            size: '14px',
            fontWeight: 'bold'
        },
        title: 'Quarters'
    },
    primaryYAxis: {
        minimum: 0,
        maximum: 40,
        interval: 10,
        title: 'Sales Value'
    },
    series: [{
        dataSource: [
            { x: 'Q1', y: 35 },
            { x: 'Q2', y: 28 },
            { x: 'Q3', y: 34 },
            { x: 'Q4', y: 32 }
        ],
        xName: 'x',
        yName: 'y',
        name: 'Quarterly Sales',
        type: 'Column'
    }],
    title: 'Labels Customization - Label Style'
}, '#element');

chart.appendTo('#element');
<!DOCTYPE html>
<html lang="en">

<head>
    <title>EJ2 Animation</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript UI Controls" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <div id='container'>
        <div id='element'></div>
    </div>
</body>

</html>

Customizing specific axis labels

Specific axis label text can be customized using the axisLabelRender event, which allows conditional formatting or dynamic text updates during label rendering.

import {
    Chart,
    ColumnSeries,
    Category,
    IAxisLabelRenderEventArgs
} from '@syncfusion/ej2-charts';

Chart.Inject(ColumnSeries, Category);

let chart: Chart = new Chart({
    primaryXAxis: {
        valueType: 'Category',
        title: 'Months'
    },
    primaryYAxis: {
        minimum: 0,
        maximum: 60,
        interval: 10,
        title: 'Sales Value'
    },
    series: [{
        dataSource: [
            { x: 'Jan', y: 15 },
            { x: 'Feb', y: 20 },
            { x: 'Mar', y: 35 },
            { x: 'Apr', y: 25 },
            { x: 'May', y: 40 },
            { x: 'Jun', y: 50 }
        ],
        xName: 'x',
        yName: 'y',
        name: 'Monthly Sales',
        type: 'Column'
    }],
    axisLabelRender: (args: IAxisLabelRenderEventArgs): void => {
        // Customize specific X-axis labels
        if (args.axis.name === 'primaryXAxis') {
            if (args.text === 'Mar') {
                args.labelStyle.color = '#ff0000';
                args.labelStyle.fontWeight = 'Bold';
                args.labelStyle.size = '16px';
            }

            if (args.text === 'Jun') {
                args.labelStyle.color = '#008000';
                args.labelStyle.fontWeight = 'Bold';
                args.labelStyle.size = '16px';
            }
        }
    },
    title: 'Customizing Specific Axis Labels'
}, '#element');

chart.appendTo('#element');
<!DOCTYPE html>
<html lang="en">

<head>
    <title>EJ2 Animation</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript UI Controls" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <div id='container'>
        <div id='element'></div>
    </div>
</body>

</html>

Line break support

The line break feature is used to display long axis label text across multiple lines. In the following example, the x value in the data source contains long text, which is split into two lines using the <br> tag.

import {
    Chart, BarSeries, DataLabel, Category,
    Tooltip
} from '@syncfusion/ej2-charts';
import { Browser } from '@syncfusion/ej2-base';
Chart.Inject(BarSeries, Category, Tooltip, DataLabel);

let chart: Chart = new Chart({
    //Initializing Primary X and YAxis
    primaryXAxis: {
        title: 'Country',
        valueType: 'Category',
        majorGridLines: { width: 0 },
        enableTrim: false,
    },

    //Initializing Primary Y Axis
    primaryYAxis:
    {
        minimum: 0,
        maximum: 800,
        labelFormat: Browser.isDevice ? '{value}' : '{value}M',
        labelStyle: {
            color: 'transparent'
        }
    },
    chartArea: {
        border: {
            width: 0
        }
    },
    //Initializing Chart Series
    series: [
        {
            type: 'Bar', tooltipMappingName: 'country',
            dataSource: [
                { x: 'Germany', y: 72, country: 'GER: 72' },
                { x: 'Russia', y: 103.1, country: 'RUS: 103.1' },
                { x: 'Brazil', y: 139.1, country: 'BRZ: 139.1' },
                { x: 'India', y: 462.1, country: 'IND: 462.1' },
                { x: 'China', y: 721.4, country: 'CHN: 721.4' },
                { x: 'United States<br>Of America', y: 286.9, country: 'USA: 286.9' },
                { x: 'Great Britain', y: 115.1, country: 'GBR: 115.1' },
                { x: 'Nigeria', y: 97.2, country: 'NGR: 97.2' },

            ],
            xName: 'x', width: 2,
            yName: 'y', marker: {
                dataLabel: {
                    visible: true,
                    position: 'Top', font: {
                        fontWeight: '600',
                        color: '#ffffff'
                    }
                }
            },
            name: 'Users'
        }
    ],
    legendSettings: {
        visible: false
    }
}, '#element');
<!DOCTYPE html>
<html lang="en">

<head>
    <title>EJ2 Animation</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript UI Controls" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <div id='container'>
        <div id='element'></div>
    </div>
</body>

</html>

Maximum labels

The maximumLabels property specifies the maximum number of axis labels to render per 100 pixels of the axis. It helps control label density based on the available axis size.

Priority:

  • When minimum, maximum, and interval are specified along with maximumLabels, the explicitly configured axis range and interval take priority.
  • When the axis range and interval are not explicitly specified, the label count is calculated based on the maximumLabels value and the axis length.
  • Recommended: Use maximumLabels to automatically control label density based on the available space. Use minimum, maximum, and interval when precise control over the axis range and label interval is required.
import { DateTime, ILoadedEventArgs, ChartTheme, ScrollBar } from '@syncfusion/ej2-charts';
import { Chart, AreaSeries, Legend, Zoom } from '@syncfusion/ej2-charts';
import { Browser } from '@syncfusion/ej2-base';
Chart.Inject(AreaSeries, DateTime, Legend, Zoom, ScrollBar);

let series1: Object[] = [];
let point1: Object;
let value: number = 80;
let i: number;
for (i = 1; i < 50; i++) {
    if (Math.random() > .5) {
        value += Math.random();
    } else {
        value -= Math.random();
    }
    point1 = { x: i, y: value.toFixed(1) };
    series1.push(point1);
}
let chart: Chart = new Chart({
    //Initializing Primary X Axis
    primaryXAxis: {
        title: 'Years',
        edgeLabelPlacement: 'Shift',
        majorGridLines: { width: 0 },
        maximumLabels: 1,
    },

    //Initializing Primary Y Axis
    primaryYAxis:
    {
        title: 'Profit ($)',
        rangePadding: 'None',
        lineStyle: { width: 0 },
        majorTickLines: { width: 0 }
    },
    chartArea: { border: { width: 0 } },

    series: [
        {
            type: 'Area',
            dataSource: series1,
            name: 'Product X',
            xName: 'x',
            yName: 'y',
            fill: 'url(#gradient-chart)',
            border: { width: 0.5, color: '#00bdae' },
            animation: { enable: false }
        },
    ],
    zoomSettings:
    {
        enableMouseWheelZooming: true,
        enablePinchZooming: true,
        enableSelectionZooming: true,
        mode: 'X',
        enableScrollbar: true
    },
    title: 'Sales History of Product X',
    legendSettings: { visible: false },
}, '#element');
<!DOCTYPE html>
<html lang="en">

<head>
    <title>EJ2 Animation</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript UI Controls" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <div id='container'>
        <div id='element'></div>
    </div>
</body>

</html>

Axis label template

The axis label template allows axis labels to be customized using HTML content. This enables conditional styling and the inclusion of dynamic elements such as icons, images, or additional contextual data. This customization is enabled by setting the template content in the labelTemplate property of the AxisModel.

import { Chart, Category, ColumnSeries } from '@syncfusion/ej2-charts';
Chart.Inject(ColumnSeries, Category);

let chartData: Object[] = [
    { Country: 'USA', Count: 46 },
    { Country: 'UK', Count: 27 },
    { Country: 'China', Count: 26 },
    { Country: 'Russia', Count: 19 },
    { Country: 'Germany', Count: 17 }
];

let chart: Chart = new Chart({
    primaryXAxis: {
        valueType: 'Category',
        labelTemplate: '#AxisLabelTemplate'
    },
    primaryYAxis: {
        valueType: 'Double'
    },
    series: [{
        dataSource: chartData, type: 'Column',
        xName: 'Country', yName: 'Count',
        marker: {
            visible: true
        }
    }],
    title: 'Olympic Medals',
    width: '70%'
});
chart.appendTo('#container');
<!DOCTYPE html>
<html lang="en">

<head>
    <title>EJ2 Animation</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript UI Controls" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <div id='container'>
        <div id='element'></div>
    </div>
    <script id="AxisLabelTemplate" type="text/x-template">
        <table>
            <tr>
                <td align="center" style="background-color: #2E8B57; font-size: 14px; color: #FFD700; font-weight: bold; padding: 5px">Country :</td>
                <td align="center" style="background-color: #4682B4; font-size: 14px; color: #FFFFFF; font-weight: bold; padding: 5px">${label}</td>
            </tr>
        </table>
    </script>
</body>

</html>

See Also