Tooltip in Angular Accumulation chart component

20 Jun 202624 minutes to read

Tooltip for the accumulation chart can be enabled by using the enable property.

import { AccumulationChartModule } from '@syncfusion/ej2-angular-charts'
import { PieSeriesService, AccumulationLegendService, AccumulationTooltipService, AccumulationAnnotationService,
  AccumulationDataLabelService } from '@syncfusion/ej2-angular-charts'


import { Component, OnInit } from '@angular/core';
import { pieData } from './datasource';
@Component({
imports: [
         AccumulationChartModule
    ],

providers: [PieSeriesService, AccumulationLegendService, AccumulationTooltipService, AccumulationDataLabelService,
     AccumulationAnnotationService],
standalone: true,
    selector: 'app-container',
    template: `<ejs-accumulationchart id="chart-container" [tooltip]='tooltip'>
        <e-accumulation-series-collection>
            <e-accumulation-series [dataSource]='piedata' xName='x' yName='y'></e-accumulation-series>
        </e-accumulation-series-collection>
    </ejs-accumulationchart>`
})
export class AppComponent implements OnInit {
    public piedata?: Object[];
     public tooltip?: Object;
    ngOnInit(): void {
        this.piedata = pieData;
        this.tooltip = {
                enable: true
                }
        };
    }
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));

Note: To use tooltip feature, inject the AccumulationTooltipService into the @NgModule.providers.

We can specify header for the tooltip using header property.

import { AccumulationChartModule } from '@syncfusion/ej2-angular-charts'
import { PieSeriesService, AccumulationLegendService, AccumulationTooltipService, AccumulationAnnotationService,
  AccumulationDataLabelService } from '@syncfusion/ej2-angular-charts'


import { Component, OnInit } from '@angular/core';
import { pieData } from './datasource';
@Component({
imports: [
         AccumulationChartModule
    ],

providers: [PieSeriesService, AccumulationLegendService, AccumulationTooltipService, AccumulationDataLabelService,
     AccumulationAnnotationService],
standalone: true,
    selector: 'app-container',
    template: `<ejs-accumulationchart id="chart-container" [tooltip]='tooltip'>
        <e-accumulation-series-collection>
            <e-accumulation-series [dataSource]='piedata' xName='x' yName='y'></e-accumulation-series>
        </e-accumulation-series-collection>
    </ejs-accumulationchart>`
})
export class AppComponent implements OnInit {
    public piedata?: Object[];
     public tooltip?: Object;
    ngOnInit(): void {
        this.piedata = pieData;
        this.tooltip = {
              enable: true, header:"Pie Chart"
                }
        };
    }
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));

Format

By default, tooltip shows information of x and y value in points. In addition to that, you can show more
information in tooltip. For example the format ${series.name} ${point.x} shows series name and point x value.

import { AccumulationChartModule } from '@syncfusion/ej2-angular-charts'
import { PieSeriesService, AccumulationLegendService, AccumulationTooltipService, AccumulationAnnotationService,
  AccumulationDataLabelService } from '@syncfusion/ej2-angular-charts'


import { Component, OnInit } from '@angular/core';
import { pieData } from './datasource';
@Component({
imports: [
         AccumulationChartModule
    ],

providers: [PieSeriesService, AccumulationLegendService, AccumulationTooltipService, AccumulationDataLabelService,
     AccumulationAnnotationService],
standalone: true,
    selector: 'app-container',
    template: `<ejs-accumulationchart id="chart-container" [tooltip]='tooltip'>
        <e-accumulation-series-collection>
            <e-accumulation-series [dataSource]='piedata' xName='x' yName='y'></e-accumulation-series>
        </e-accumulation-series-collection>
    </ejs-accumulationchart>`
})
export class AppComponent implements OnInit {
    public piedata?: Object[];
     public tooltip?: Object;
    ngOnInit(): void {
        this.piedata = pieData;
        this.tooltip = {
              enable: true,  format: '${point.x} : <b>${point.y}%</b>'
                }
        };
    }
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));

Inline tooltip formatting

The tooltip content can be formatted directly within the format property by adding DateTime or number format specifiers to supported tooltip tokens. This allows you to control how point and series values are displayed without using additional events.

A format specifier can be applied to a tooltip token by adding a colon (:) followed by the required format.

For example:

public tooltip = {
    enable: true,
    format: '${series.name} (${series.type})<br>${point.x:MMM yyyy} : ${point.y:n2}<br>Size: ${point.size}<br>Opacity: ${series.opacity}'
};

In the above example, point.y is displayed with two decimal places, point.percentage is displayed in percentage format, and series.opacity displays the opacity value applied to the series.

Inline formatting can be applied to the following tooltip tokens:

  • point.x – Specifies the x-value or category value of the accumulation chart point.
  • point.y – Specifies the numeric y-value of the accumulation chart point.
  • point.percentage – Specifies the percentage contribution of the point value in the accumulation chart.
  • point.text – Specifies the text value mapped to the point, when text mapping is configured.
  • point.tooltip – Specifies the tooltip value mapped from the data source, when tooltip mapping is configured.
  • point.index – Specifies the index position of the point in the accumulation chart.
  • point.color – Specifies the fill color applied to the point.
  • point.visible – Specifies the visibility state of the point.
  • series.name – Specifies the name assigned to the accumulation chart series.
  • series.type – Specifies the rendering type of the accumulation chart series, such as Pie, Doughnut, Pyramid, or Funnel.
  • series.opacity – Specifies the opacity value applied to the accumulation chart series. This value controls the visual transparency of the series and can be customized in the series configuration.

Important: The availability of point-specific tokens depends on the values configured in the data source and the accumulation chart series type. For example, point.percentage is useful for pie and doughnut charts, while point.text and point.tooltip depend on the corresponding field mappings. The series.name and series.type tokens return string values, so DateTime or number formatting is not applied to these tokens.

The following format types are supported:

  • DateTime formats such as MMM yyyy, MM:yy, and dd MMM
  • Number formats such as:
    • n2 – number with two decimal places
    • n0 – number without decimals
    • c2 – currency format
    • p1 – percentage format
    • e1 – exponential notation

If the specified format does not match the resolved value type, the original value is displayed.

import { AccumulationChartModule } from '@syncfusion/ej2-angular-charts'
import { PieSeriesService, AccumulationTooltipService } from '@syncfusion/ej2-angular-charts'
import { Component, OnInit } from '@angular/core';

@Component({
imports: [AccumulationChartModule],
providers: [ AccumulationTooltipService, PieSeriesService ],
standalone: true,
    selector: 'app-container',
    template: `<ejs-accumulationchart id="piechart" [tooltip]="tooltip">
                    <e-accumulation-series-collection>
                        <e-accumulation-series type="Pie" [dataSource]="chartData" xName="x" yName="y" radius="100%"></e-accumulation-series>
                    </e-accumulation-series-collection>
                </ejs-accumulationchart>`
})
export class AppComponent implements OnInit {
    
public chartData: Object[] = [
    { x: new Date(2024, 0, 1), y: 3 },
    { x: new Date(2024, 1, 1), y: 3.5 },
    { x: new Date(2024, 2, 1), y: 7 },
    { x: new Date(2024, 3, 1), y: 13.5 },
    { x: new Date(2024, 4, 1), y: 19 },
    { x: new Date(2024, 5, 1), y: 23.5 },
    { x: new Date(2024, 6, 1), y: 26 },
    { x: new Date(2024, 7, 1), y: 25 },
    { x: new Date(2024, 8, 1), y: 21 },
    { x: new Date(2024, 9, 1), y: 15 }
  ];

  public tooltip: Object = {
    enable: true,
    format: '${point.x:MMM yyyy} : <b>${point.y:n2}%</b>'
  };

}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));

Tooltip template

Any HTML element can be displayed in the tooltip by using the template property.

import { AccumulationChartModule } from '@syncfusion/ej2-angular-charts'
import { PieSeriesService, AccumulationLegendService, AccumulationTooltipService, AccumulationAnnotationService,
  AccumulationDataLabelService } from '@syncfusion/ej2-angular-charts'


import { Component, OnInit } from '@angular/core';
import { pieData } from './datasource';
@Component({
imports: [
         AccumulationChartModule
    ],

providers: [PieSeriesService, AccumulationLegendService, AccumulationTooltipService, AccumulationDataLabelService,
     AccumulationAnnotationService],
standalone: true,
    selector: 'app-container',
    template: `<ejs-accumulationchart id="chart-container" [tooltip]='tooltip'>
        <e-accumulation-series-collection>
            <e-accumulation-series [dataSource]='piedata' xName='x' yName='y'></e-accumulation-series>
        </e-accumulation-series-collection>
    </ejs-accumulationchart>`
})
export class AppComponent implements OnInit {
    public piedata?: Object[];
     public tooltip?: Object;
    ngOnInit(): void {
        this.piedata = pieData;
        this.tooltip = {
              enable: true,  template: "<div id='templateWrap' style='background-color:#bd18f9;border-radius: 3px; float: right;padding: 2px;line-height: 20px;text-align: center;'>"+
        "<img src='https://ej2.syncfusion.com/demos/src/chart/images/sunny.png' />" +
        "<div style='color:white; font-family:Roboto; font-style: medium; fontp-size:14px;float: right;padding: 2px;line-height: 20px;text-align: center;padding-right:6px'><span>${y}</span></div></div>"
                }
        };
    }
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));

Fixed tooltip

By default, tooltip track the mouse movement, but you can set a fixed position for the tooltip by using the location property.

import { AccumulationChartModule } from '@syncfusion/ej2-angular-charts'
import { PieSeriesService, AccumulationLegendService, AccumulationTooltipService, AccumulationAnnotationService,
  AccumulationDataLabelService } from '@syncfusion/ej2-angular-charts'


import { Component, OnInit } from '@angular/core';
import { pieData } from './datasource';
@Component({
imports: [
         AccumulationChartModule
    ],

providers: [PieSeriesService, AccumulationLegendService, AccumulationTooltipService, AccumulationDataLabelService,
     AccumulationAnnotationService],
standalone: true,
    selector: 'app-container',
    template: `<ejs-accumulationchart id="chart-container" [tooltip]='tooltip'>
        <e-accumulation-series-collection>
            <e-accumulation-series [dataSource]='piedata' xName='x' yName='y'></e-accumulation-series>
        </e-accumulation-series-collection>
    </ejs-accumulationchart>`
})
export class AppComponent implements OnInit {
    public piedata?: Object[];
     public tooltip?: Object;
    ngOnInit(): void {
        this.piedata = pieData;
        this.tooltip = {
            enable: true,
            location: { x: 200, y: 20 }
        }
    };
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));

Customization

The fill and border properties are used to customize the background color and border of the tooltip respectively. The textStyle property in the tooltip is used to customize the font of the tooltip text. The highlightColor property can be used to change the color of the data point when hovering.

import { AccumulationChartModule } from '@syncfusion/ej2-angular-charts'
import { PieSeriesService, AccumulationLegendService, AccumulationTooltipService, AccumulationAnnotationService,
  AccumulationDataLabelService } from '@syncfusion/ej2-angular-charts'

import { Component, OnInit } from '@angular/core';
import { pieData } from './datasource';
@Component({
imports: [
         AccumulationChartModule
    ],

providers: [PieSeriesService, AccumulationLegendService, AccumulationTooltipService, AccumulationDataLabelService,
     AccumulationAnnotationService],
standalone: true,
    selector: 'app-container',
    template: `<ejs-accumulationchart id="chart-container" [tooltip]='tooltip' highlightColor="red" [legendSettings]='legendSettings'>
        <e-accumulation-series-collection>
            <e-accumulation-series [dataSource]='piedata' xName='x' yName='y'></e-accumulation-series>
        </e-accumulation-series-collection>
    </ejs-accumulationchart>`
})
export class AppComponent implements OnInit {
    public piedata: Object[] = [];
     public tooltip?: Object;
     public legendSettings?: Object;
    ngOnInit(): void {
        this.piedata = pieData;
        this.tooltip = {
              enable: true };
              this.legendSettings = { visible: false}
        };
    }
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));

Tooltip mapping name

By default, tooltip shows information of x and y value in points. You can show more information from datasource in tooltip by using the tooltipMappingName property of the tooltip.
You can use the ${point.tooltip} as place holders to display the specified tooltip content.

import { AccumulationChartModule } from '@syncfusion/ej2-angular-charts'
import { PieSeriesService, AccumulationLegendService, AccumulationTooltipService, AccumulationAnnotationService,
  AccumulationDataLabelService } from '@syncfusion/ej2-angular-charts'


import { Component, OnInit } from '@angular/core';
@Component({
imports: [
         AccumulationChartModule
    ],

providers: [PieSeriesService, AccumulationLegendService, AccumulationTooltipService, AccumulationDataLabelService,
     AccumulationAnnotationService],
standalone: true,
    selector: 'app-container',
    template: `<ejs-accumulationchart id="chart-container" [tooltip]='tooltip'>
        <e-accumulation-series-collection>
            <e-accumulation-series [dataSource]='piedata' xName='x' yName='y' tooltipMappingName='text'></e-accumulation-series>
        </e-accumulation-series-collection>
    </ejs-accumulationchart>`
})
export class AppComponent implements OnInit {
    public piedata?: Object[];
    public tooltip?: Object;
    ngOnInit(): void {
        this.piedata = [{ x: 'Jan', y: 13, text: 'Jan: 13' }, { x: 'Feb', y: 13, text: 'Feb: 13' },
                        { x: 'Mar', y: 17, text: 'Mar: 17' }, { x: 'Apr', y: 13.5, text: 'Apr: 13.5' }
         ];
         this.tooltip = {
              enable: true, format: '${point.tooltip}'
                }
               };
    }
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));

To customize individual tooltip

Using tooltipRender event, you can customize a tooltip for particular point. event, you can customize a tooltip for particular point.

import { AccumulationChartModule } from '@syncfusion/ej2-angular-charts'
import { PieSeriesService, AccumulationLegendService, AccumulationTooltipService, AccumulationAnnotationService,
  AccumulationDataLabelService } from '@syncfusion/ej2-angular-charts'


import { Component, OnInit } from '@angular/core';
import { pieData } from './datasource';
import { IAccTooltipRenderEventArgs } from '@syncfusion/ej2-charts';
import { FontModel } from '@syncfusion/ej2-angular-charts';
@Component({
imports: [
         AccumulationChartModule
    ],

providers: [PieSeriesService, AccumulationLegendService, AccumulationTooltipService, AccumulationDataLabelService,
     AccumulationAnnotationService],
standalone: true,
    selector: 'app-container',
    template: `<ejs-accumulationchart id="chart-container" [tooltip]='tooltip' (tooltipRender)="ontooltipRender($event)">
        <e-accumulation-series-collection>
            <e-accumulation-series [dataSource]='piedata' xName='x' yName='y'></e-accumulation-series>
        </e-accumulation-series-collection>
    </ejs-accumulationchart>`
})
export class AppComponent implements OnInit {
    public piedata?: Object[];
    public tooltip?: Object;
    public ontooltipRender?: Function;
    ngOnInit(): void {
        this.piedata = pieData;
        this.tooltip = {
            enable: true
        }
        this.ontooltipRender = (args: IAccTooltipRenderEventArgs) => {
            if (args.point.index === 3) {
                args.text = args.point.x + '' + ':' + args.point.y + '' + ' ' +'customtext';
                (args.textStyle as FontModel).color = '#f48042';
            }
        }
    };
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));

Enable highlight

By setting the enableHighlight property to true, the hovered pie slice is highlighted, while the remaining slices are dimmed, enhancing focus and clarity.

import { AccumulationChartModule } from '@syncfusion/ej2-angular-charts';
import { PieSeriesService, AccumulationTooltipService, AccumulationLegendService } from '@syncfusion/ej2-angular-charts';
import { Component, OnInit } from '@angular/core';
import { pieData } from './datasource';

@Component({
    imports: [AccumulationChartModule],
    providers: [PieSeriesService, AccumulationTooltipService, AccumulationLegendService],
    standalone: true,
    selector: 'app-container',
    template: `<ejs-accumulationchart id="chart-container" [tooltip]='tooltip' [legendSettings]='legendSettings'>
        <e-accumulation-series-collection>
            <e-accumulation-series [dataSource]='piedata' xName='x' yName='y'></e-accumulation-series>
        </e-accumulation-series-collection>
    </ejs-accumulationchart>`
})
export class AppComponent implements OnInit {
    public piedata?: Object[];
    public tooltip?: Object;
    public legendSettings?: Object;
    ngOnInit(): void {
        this.piedata = pieData;
        this.tooltip = {
            enable: true,
            enableHighlight: true
        };
        this.legendSettings = { visible: false };
    };
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));

Follow pointer

The follow pointer feature enables the tooltip to follow the mouse cursor or touch pointer as users interact with the accumulation chart. This provides a more dynamic and intuitive experience by keeping the tooltip close to the user’s point of interaction.

Enable this feature by setting the followPointer property to true:

import { Component, OnInit } from '@angular/core';
import { AccumulationChartModule } from '@syncfusion/ej2-angular-charts';
import { PieSeriesService, AccumulationTooltipService, AccumulationDataLabelService } from '@syncfusion/ej2-angular-charts';

import { data } from './datasource';

@Component({
    imports: [
        AccumulationChartModule
    ],
    providers: [PieSeriesService, AccumulationTooltipService, AccumulationDataLabelService],
    standalone: true,
    selector: 'app-container',
    template: `<ejs-accumulationchart id="pie-chart" [enableAnimation]="enableAnimation"
        [tooltip]="tooltip">
        <e-accumulation-series-collection>
            <e-accumulation-series [dataSource]="chartData" name="Browser" xName="x" yName="y"
                borderRadius="3">
            </e-accumulation-series>
        </e-accumulation-series-collection>
    </ejs-accumulationchart>`
})
export class AppComponent implements OnInit {
    public chartData?: Object[];
    public enableAnimation?: boolean;
    public tooltip?: Object;

    ngOnInit(): void {
        this.chartData = data;

        this.enableAnimation = true;

        this.tooltip = {
            enable: true,
            format: '<b>${point.x}</b><br>Percentage: <b>${point.y}%</b>',
            followPointer: true
        };
    }
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';

bootstrapApplication(AppComponent).catch((err) => console.error(err));
export let data = [
    { 'x': 'Coal', y: 34.4, text: 'Coal: 34.4%' },
    { 'x': 'Natural Gas', y: 22.1, text: 'Natural Gas: 22.1%' },
    { 'x': 'Hydro', y: 14.4, text: 'Hydro: 14.4%' },
    { 'x': 'Nuclear', y: 9.0, text: 'Nuclear: 9.0%' },
    { 'x': 'Wind', y: 8.1, text: 'Wind: 8.1%' },
    { 'x': 'Others', y: 12.0, text: 'Others: 12.0%' }
];