Tooltip in React Accumulation chart component
20 Jun 202624 minutes to read
Tooltip for the accumulation chart can be enabled by using the enable property.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { AccumulationChartComponent, AccumulationSeriesCollectionDirective, AccumulationSeriesDirective, AccumulationTooltip, Inject } from '@syncfusion/ej2-react-charts';
import { accData } from '../datasource.ts';
function App() {
return <AccumulationChartComponent id='charts' tooltip={{ enable: true }}>
<Inject services={[AccumulationTooltip]}/>
<AccumulationSeriesCollectionDirective>
<AccumulationSeriesDirective dataSource={accData} xName='x' yName='y'>
</AccumulationSeriesDirective>
</AccumulationSeriesCollectionDirective>
</AccumulationChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));import * as React from "react";
import * as ReactDOM from "react-dom";
import { AccumulationChartComponent, AccumulationSeriesCollectionDirective, AccumulationSeriesDirective,
AccumulationTooltip, Inject,TooltipSettingsModel} from'@syncfusion/ej2-react-charts';
import { accData } from '../datasource.ts';
function App() {
return <AccumulationChartComponent id='charts' tooltip={{ enable: true }}>
<Inject services={[AccumulationTooltip]} />
<AccumulationSeriesCollectionDirective>
<AccumulationSeriesDirective dataSource={accData} xName='x' yName='y'>
</AccumulationSeriesDirective>
</AccumulationSeriesCollectionDirective>
</AccumulationChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));Note:To use tooltip feature , we need to inject
AccumulationTooltipmodule into theservices.
Header
We can specify header for the tooltip using header property.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { AccumulationChartComponent, AccumulationSeriesCollectionDirective, AccumulationSeriesDirective, AccumulationTooltip, Inject } from '@syncfusion/ej2-react-charts';
import { accData } from '../datasource.ts';
function App() {
return <AccumulationChartComponent id='charts' tooltip={{ enable: true, header: "Pie Chart" }}>
<Inject services={[AccumulationTooltip]}/>
<AccumulationSeriesCollectionDirective>
<AccumulationSeriesDirective dataSource={accData} xName='x' yName='y'>
</AccumulationSeriesDirective>
</AccumulationSeriesCollectionDirective>
</AccumulationChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));import * as React from "react";
import * as ReactDOM from "react-dom";
import { AccumulationChartComponent, AccumulationSeriesCollectionDirective, AccumulationSeriesDirective,
AccumulationTooltip, Inject }
from'@syncfusion/ej2-react-charts';
import { accData } from '../datasource.ts';
function App() {
return <AccumulationChartComponent id='charts' tooltip={{ enable: true, header: "Pie Chart" }}>
<Inject services={[AccumulationTooltip]} />
<AccumulationSeriesCollectionDirective>
<AccumulationSeriesDirective dataSource={accData} xName='x' yName='y'>
</AccumulationSeriesDirective>
</AccumulationSeriesCollectionDirective>
</AccumulationChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));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 * as React from "react";
import * as ReactDOM from "react-dom";
import { AccumulationChartComponent, AccumulationSeriesCollectionDirective, AccumulationSeriesDirective, AccumulationTooltip, Inject, AccumulationLegend } from '@syncfusion/ej2-react-charts';
import { accData } from '../datasource.ts';
function App() {
return <AccumulationChartComponent id='charts' tooltip={{ enable: true, format: '${point.x} : <b>${point.y}%</b>' }}>
<Inject services={[AccumulationLegend, AccumulationTooltip]}/>
<AccumulationSeriesCollectionDirective>
<AccumulationSeriesDirective dataSource={accData} xName='x' yName='y'>
</AccumulationSeriesDirective>
</AccumulationSeriesCollectionDirective>
</AccumulationChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));import * as React from "react";
import * as ReactDOM from "react-dom";
import { AccumulationChartComponent, AccumulationSeriesCollectionDirective,
AccumulationSeriesDirective, AccumulationTooltip, Inject, AccumulationLegend} from'@syncfusion/ej2-react-charts';
import { accData } from '../datasource.ts';
function App() {
return <AccumulationChartComponent id='charts' tooltip={{ enable: true, format: '${point.x} : <b>${point.y}%</b>' }}>
<Inject services={[AccumulationLegend, AccumulationTooltip]} />
<AccumulationSeriesCollectionDirective>
<AccumulationSeriesDirective dataSource={accData} xName='x' yName='y'>
</AccumulationSeriesDirective>
</AccumulationSeriesCollectionDirective>
</AccumulationChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));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:
const tooltip = {
enable: true,
format: '${series.name}<br>${point.x} : ${point.y:n2}<br>Percentage: ${point.percentage:p1}<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 asPie,Doughnut,Pyramid, orFunnel. -
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, anddd 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 * as React from "react";
import * as ReactDOM from "react-dom";
import { AccumulationChartComponent, AccumulationSeriesCollectionDirective, AccumulationSeriesDirective, Inject, AccumulationTooltip } from '@syncfusion/ej2-react-charts';
import { labelData } from './datasource';
function App() {
return (
<AccumulationChartComponent id='pie-chart' tooltip={{ enable: true, format: '${point.x:MMM yyyy} : <b>${point.y:n2}%</b>' }}>
<Inject services={[AccumulationTooltip,]} />
<AccumulationSeriesCollectionDirective>
<AccumulationSeriesDirective dataSource={labelData} xName='x' yName='y'/>
</AccumulationSeriesCollectionDirective>
</AccumulationChartComponent>
);
}
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));import * as React from "react";
import * as ReactDOM from "react-dom";
import { AccumulationChartComponent, AccumulationSeriesCollectionDirective, AccumulationSeriesDirective, Inject, AccumulationTooltip } from '@syncfusion/ej2-react-charts';
import { labelData } from './datasource';
function App() {
return (
<AccumulationChartComponent id='pie-chart' tooltip={{ enable: true, format: '${point.x:MMM yyyy} : <b>${point.y:n2}%</b>' }}>
<Inject services={[AccumulationTooltip]} />
<AccumulationSeriesCollectionDirective>
<AccumulationSeriesDirective dataSource={labelData} xName='x' yName='y' />
</AccumulationSeriesCollectionDirective>
</AccumulationChartComponent>
);
}
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));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 * as React from "react";
import * as ReactDOM from "react-dom";
import { AccumulationChartComponent, AccumulationSeriesCollectionDirective, AccumulationSeriesDirective, AccumulationTooltip, Inject, AccumulationLegend } from '@syncfusion/ej2-react-charts';
import { accData } from '../datasource.ts';
function App() {
return <AccumulationChartComponent id='charts' tooltip={{ enable: true, format: '${point.tooltip}' }}>
<Inject services={[AccumulationLegend, AccumulationTooltip]}/>
<AccumulationSeriesCollectionDirective>
<AccumulationSeriesDirective dataSource={accData} xName='x' yName='y' tooltipMappingName='text'>
</AccumulationSeriesDirective>
</AccumulationSeriesCollectionDirective>
</AccumulationChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));import * as React from "react";
import * as ReactDOM from "react-dom";
import { AccumulationChartComponent, AccumulationSeriesCollectionDirective,
AccumulationSeriesDirective, AccumulationTooltip, Inject, AccumulationLegend}
from'@syncfusion/ej2-react-charts';
import { accData } from '../datasource.ts';
function App() {
return <AccumulationChartComponent id='charts' tooltip={{ enable: true, format: '${point.tooltip}' }}>
<Inject services={[AccumulationLegend, AccumulationTooltip]} />
<AccumulationSeriesCollectionDirective>
<AccumulationSeriesDirective dataSource={accData} xName='x' yName='y' tooltipMappingName='text'>
</AccumulationSeriesDirective>
</AccumulationSeriesCollectionDirective>
</AccumulationChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));Tooltip template
Any HTML element can be displayed in the tooltip by using the template property.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { AccumulationChartComponent, AccumulationSeriesCollectionDirective, AccumulationSeriesDirective, AccumulationTooltip, Inject } from '@syncfusion/ej2-react-charts';
import { accData } from '../datasource.ts';
function App() {
const template = chartTemplate;
function chartTemplate(args) {
return (<div style={{ border: '1px solid black', backgroundColor: 'red', padding: '2px', float: 'right', lineHeight: '20px', textAlign: 'center' }}>
<img src='sun_annotation.png'/>
<div style={{ color: 'blue', padding: '2px', fontSize: '14px', fontStyle: 'medium', fontFamily: 'Roboto', float: 'right', lineHeight: '20px', textAlign: 'center', paddingRight: '6px' }}>
<span>{args.y}</span>
</div>
</div>);
}
return <AccumulationChartComponent id='charts' tooltip={{ enable: true, template: template }}>
<Inject services={[AccumulationTooltip]}/>
<AccumulationSeriesCollectionDirective>
<AccumulationSeriesDirective dataSource={accData} xName='x' yName='y'>
</AccumulationSeriesDirective>
</AccumulationSeriesCollectionDirective>
</AccumulationChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));import * as React from "react";
import * as ReactDOM from "react-dom";
import { AccumulationChartComponent, AccumulationSeriesCollectionDirective, AccumulationSeriesDirective,
AccumulationTooltip, Inject} from'@syncfusion/ej2-react-charts';
import { accData } from '../datasource.ts';
function App() {
const template:any =chartTemplate;
function chartTemplate(args:any){
return (<div style={{ border:'1px solid black', backgroundColor:'red', padding:'2px',float:'right', lineHeight:'20px',textAlign:'center'}}>
<img src='sun_annotation.png' />
<div style={{ color:'blue', padding:'2px',fontSize:'14px', fontStyle:'medium',fontFamily:'Roboto' ,float:'right',lineHeight:'20px',textAlign:'center',paddingRight:'6px'}}>
<span>{args.y}</span>
</div>
</div>
);
}
return <AccumulationChartComponent id='charts' tooltip={{ enable: true, template: template }}>
<Inject services={[AccumulationTooltip]} />
<AccumulationSeriesCollectionDirective>
<AccumulationSeriesDirective dataSource={accData} xName='x' yName='y'>
</AccumulationSeriesDirective>
</AccumulationSeriesCollectionDirective>
</AccumulationChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));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 * as React from "react";
import * as ReactDOM from "react-dom";
import { AccumulationChartComponent, AccumulationSeriesCollectionDirective, AccumulationSeriesDirective, AccumulationTooltip, Inject } from '@syncfusion/ej2-react-charts';
import { accData } from '../datasource.ts';
function App() {
return <AccumulationChartComponent id='charts' tooltip={{ enable: true, location: { x: 200, y: 20 } }}>
<Inject services={[AccumulationTooltip]}/>
<AccumulationSeriesCollectionDirective>
<AccumulationSeriesDirective dataSource={accData} xName='x' yName='y'>
</AccumulationSeriesDirective>
</AccumulationSeriesCollectionDirective>
</AccumulationChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));import * as React from "react";
import * as ReactDOM from "react-dom";
import { AccumulationChartComponent, AccumulationSeriesCollectionDirective, AccumulationSeriesDirective,
AccumulationTooltip, Inject} from'@syncfusion/ej2-react-charts';
import { accData } from '../datasource.ts';
function App() {
return <AccumulationChartComponent id='charts' tooltip={{ enable: true, location: { x: 200, y: 20 } }}>
<Inject services={[AccumulationTooltip]} />
<AccumulationSeriesCollectionDirective>
<AccumulationSeriesDirective dataSource={accData} xName='x' yName='y'>
</AccumulationSeriesDirective>
</AccumulationSeriesCollectionDirective>
</AccumulationChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));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 * as React from "react";
import * as ReactDOM from "react-dom";
import { AccumulationChartComponent, AccumulationSeriesCollectionDirective, AccumulationSeriesDirective, AccumulationTooltip, Inject } from '@syncfusion/ej2-react-charts';
import { accData } from '../datasource.ts';
function App() {
return <AccumulationChartComponent id='charts' tooltip={{
enable: true, format: '${series.name} ${point.x} : ${point.y}',
//fill for tooltip
fill: '#7bb4eb',
//border for tooltip
border: {
width: 2,
color: 'grey'
}
}} highlightColor='red'>
<Inject services={[AccumulationTooltip]}/>
<AccumulationSeriesCollectionDirective>
<AccumulationSeriesDirective dataSource={accData} xName='x' yName='y'>
</AccumulationSeriesDirective>
</AccumulationSeriesCollectionDirective>
</AccumulationChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));import * as React from "react";
import * as ReactDOM from "react-dom";
import { AccumulationChartComponent, AccumulationSeriesCollectionDirective, IAccTooltipRenderEventArgs,
AccumulationSeriesDirective, AccumulationTooltip, Inject} from'@syncfusion/ej2-react-charts';
import { accData } from '../datasource.ts';
function App() {
return <AccumulationChartComponent id='charts' tooltip={{
enable: true, format: '${series.name} ${point.x} : ${point.y}',
//fill for tooltip
fill: '#7bb4eb',
//border for tooltip
border: {
width: 2,
color: 'grey'
}
}} highlightColor='red'>
<Inject services={[AccumulationTooltip]} />
<AccumulationSeriesCollectionDirective>
<AccumulationSeriesDirective dataSource={accData} xName='x' yName='y'>
</AccumulationSeriesDirective>
</AccumulationSeriesCollectionDirective>
</AccumulationChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));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 * as React from "react";
import * as ReactDOM from "react-dom";
import { AccumulationChartComponent, AccumulationSeriesCollectionDirective, AccumulationSeriesDirective, AccumulationTooltip, Inject, AccumulationLegend } from '@syncfusion/ej2-react-charts';
import { accData } from '../datasource.ts';
function App() {
const tooltipRender = (args) => {
if (args.point.index === 3) {
args.text = args.point.x + '' + ':' + args.point.y + '' + ' ' + 'customtext';
args.textStyle.color = '#f48042';
}
};
return <AccumulationChartComponent id='charts' tooltip={{ enable: true }} tooltipRender={tooltipRender}>
<Inject services={[AccumulationLegend, AccumulationTooltip]}/>
<AccumulationSeriesCollectionDirective>
<AccumulationSeriesDirective dataSource={accData} xName='x' yName='y'>
</AccumulationSeriesDirective>
</AccumulationSeriesCollectionDirective>
</AccumulationChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));import * as React from "react";
import * as ReactDOM from "react-dom";
import { AccumulationChartComponent, AccumulationSeriesCollectionDirective, IAccTooltipRenderEventArgs,
AccumulationSeriesDirective, AccumulationTooltip, Inject, AccumulationLegend,TooltipSettingsModel}from'@syncfusion/ej2-react-charts';
import { accData } from '../datasource.ts';
function App() {
const tooltipRender: EmitType<IAccTooltipRenderEventArgs> = (args: IAccTooltipRenderEventArgs): void => {
if (args.point.index === 3) {
args.text = args.point.x + '' + ':' + args.point.y + '' + ' ' + 'customtext';
args.textStyle.color = '#f48042';
}
};
return <AccumulationChartComponent id='charts' tooltip={{ enable: true }} tooltipRender={tooltipRender}>
<Inject services={[AccumulationLegend, AccumulationTooltip]} />
<AccumulationSeriesCollectionDirective>
<AccumulationSeriesDirective dataSource={accData} xName='x' yName='y'>
</AccumulationSeriesDirective>
</AccumulationSeriesCollectionDirective>
</AccumulationChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));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 * as React from "react";
import * as ReactDOM from "react-dom";
import { AccumulationChartComponent, AccumulationSeriesCollectionDirective, AccumulationSeriesDirective, Inject, AccumulationTooltip, PieSeries, AccumulationLegend } from '@syncfusion/ej2-react-charts';
import { data } from '../datasource.ts';
function App() {
const tooltip = {
enable: true,
enableHighlight: true
};
const legendSettings = { visible: false };
return (
<AccumulationChartComponent id="container" tooltip={tooltip} legendSettings={legendSettings}>
<Inject services={[AccumulationTooltip, PieSeries, AccumulationLegend]} />
<AccumulationSeriesCollectionDirective>
<AccumulationSeriesDirective dataSource={data} xName='x' yName='y'>
</AccumulationSeriesDirective>
</AccumulationSeriesCollectionDirective>
</AccumulationChartComponent>
)
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));import * as React from "react";
import * as ReactDOM from "react-dom";
import { AccumulationChartComponent, AccumulationSeriesCollectionDirective, AccumulationSeriesDirective, Inject, AccumulationTooltip, TooltipSettingsModel, PieSeries, AccumulationLegend, LegendSettingsModel } from '@syncfusion/ej2-react-charts';
import { data } from '../datasource.ts';
function App() {
const tooltip: TooltipSettingsModel = {
enable: true,
enableHighlight: true
};
const legendSettings: LegendSettingsModel = { visible: false };
return (
<AccumulationChartComponent id="container" tooltip={tooltip} legendSettings={legendSettings}>
<Inject services={[AccumulationTooltip, PieSeries, AccumulationLegend]} />
<AccumulationSeriesCollectionDirective>
<AccumulationSeriesDirective dataSource={data} xName='x' yName='y'>
</AccumulationSeriesDirective>
</AccumulationSeriesCollectionDirective>
</AccumulationChartComponent>
)
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));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:
tooltip: {
enable: true,
followPointer: true
}import * as React from "react";
import * as ReactDOM from "react-dom";
import { AccumulationChartComponent, AccumulationSeriesCollectionDirective, AccumulationSeriesDirective, Inject, AccumulationTooltip, PieSeries, AccumulationDataLabel} from '@syncfusion/ej2-react-charts';
import { data } from './datasource';
function App() {
return (
<AccumulationChartComponent id='pie-chart' enableAnimation={true} tooltip={{ enable: true, format: '<b>${point.x}</b><br>Percentage: <b>${point.y}%</b>', followPointer: true }}>
<Inject services={[PieSeries, AccumulationTooltip, AccumulationDataLabel]} />
<AccumulationSeriesCollectionDirective>
<AccumulationSeriesDirective dataSource={data} name='Browser' xName='x' yName='y' borderRadius={3} />
</AccumulationSeriesCollectionDirective>
</AccumulationChartComponent>
);
}
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));import * as React from "react";
import * as ReactDOM from "react-dom";
import { AccumulationChartComponent, AccumulationSeriesCollectionDirective, AccumulationSeriesDirective, Inject, AccumulationTooltip, PieSeries, AccumulationDataLabel} from '@syncfusion/ej2-react-charts';
import { data } from './datasource';
function App() {
return (
<AccumulationChartComponent id='pie-chart' enableAnimation={true} tooltip={{ enable: true, format: '<b>${point.x}</b><br>Percentage: <b>${point.y}%</b>', followPointer: true }}>
<Inject services={[PieSeries, AccumulationTooltip, AccumulationDataLabel]} />
<AccumulationSeriesCollectionDirective>
<AccumulationSeriesDirective dataSource={data} name='Browser' xName='x' yName='y' borderRadius={3} />
</AccumulationSeriesCollectionDirective>
</AccumulationChartComponent>
);
}
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));