How can I help you?
Tooltip in React Chart component
3 Feb 202624 minutes to read
The chart displays detailed information about a data point through a tooltip when the mouse pointer moves over the point.
Default tooltip
By default, the tooltip is not visible. You can enable the tooltip by setting the enable property to true and by injecting Tooltip into the provide.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, DateTime, Tooltip, DataLabel, StepLineSeries } from '@syncfusion/ej2-react-charts';
import { data } from './datasource';
function App() {
const primaryxAxis = { valueType: 'DateTime' };
const tooltip = { enable: true };
const marker = { visible: true, width: 10, height: 10 };
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} tooltip={tooltip} title='Unemployment Rates 1975-2010'>
<Inject services={[StepLineSeries, Legend, Tooltip, DataLabel, DateTime]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={data} xName='x' yName='y' name='China' width={2} type='StepLine' marker={marker}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));import * as React from "react";
import * as ReactDOM from "react-dom";
import { AxisModel, ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject,TooltipSettingsModel,
Legend, DateTime, Tooltip, DataLabel, StepLineSeries}
from'@syncfusion/ej2-react-charts';
import { data } from './datasource';
function App() {
const primaryxAxis: AxisModel = { valueType: 'DateTime' };
const tooltip: TooltipSettingsModel = { enable: true };
const marker = { visible: true, width: 10, height: 10 };
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
tooltip={tooltip}
title='Unemployment Rates 1975-2010'>
<Inject services={[StepLineSeries, Legend, Tooltip, DataLabel, DateTime]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={data} xName='x' yName='y' name='China' width={2}
type='StepLine' marker={marker}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));export let data = [
{ x: new Date(1975, 0, 1), y: 16, y1: 10, y2: 4.5 },
{ x: new Date(1980, 0, 1), y: 12.5, y1: 7.5, y2: 5 },
{ x: new Date(1985, 0, 1), y: 19, y1: 11, y2: 6.5 },
{ x: new Date(1990, 0, 1), y: 14.4, y1: 7, y2: 4.4 },
{ x: new Date(1995, 0, 1), y: 11.5, y1: 8, y2: 5 },
{ x: new Date(2000, 0, 1), y: 14, y1: 6, y2: 1.5 },
{ x: new Date(2005, 0, 1), y: 10, y1: 3.5, y2: 2.5 },
{ x: new Date(2010, 0, 1), y: 16, y1: 7, y2: 3.7 }
];export let data: Object[] = [
{ x: new Date(1975, 0, 1), y: 16, y1: 10, y2: 4.5 },
{ x: new Date(1980, 0, 1), y: 12.5, y1: 7.5, y2: 5 },
{ x: new Date(1985, 0, 1), y: 19, y1: 11, y2: 6.5 },
{ x: new Date(1990, 0, 1), y: 14.4, y1: 7, y2: 4.4 },
{ x: new Date(1995, 0, 1), y: 11.5, y1: 8, y2: 5 },
{ x: new Date(2000, 0, 1), y: 14, y1: 6, y2: 1.5 },
{ x: new Date(2005, 0, 1), y: 10, y1: 3.5, y2: 2.5 },
{ x: new Date(2010, 0, 1), y: 16, y1: 7, y2: 3.7 }
];Fixed tooltip
By default, the tooltip tracks the mouse movement. You can render the tooltip at a fixed position by using the location property.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, DateTime, Tooltip, StepLineSeries } from '@syncfusion/ej2-react-charts';
import { data } from './datasource';
function App() {
const primaryxAxis = { valueType: 'DateTime' };
const tooltip = { enable: true, location: { x: 120, y: 20 } };
const marker = { visible: true, width: 10, height: 10 };
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} tooltip={tooltip} title='Unemployment Rates 1975-2010'>
<Inject services={[StepLineSeries, Tooltip, DateTime]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={data} xName='x' yName='y' name='China' width={2} type='StepLine' marker={marker}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));import * as React from "react";
import * as ReactDOM from "react-dom";
import {
AxisModel, ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, TooltipSettingsModel,
DateTime, Tooltip, StepLineSeries
}
from '@syncfusion/ej2-react-charts';
import { data } from './datasource';
function App() {
const primaryxAxis: AxisModel = { valueType: 'DateTime' };
const tooltip: TooltipSettingsModel = { enable: true, location: { x: 120, y: 20 } };
const marker = { visible: true, width: 10, height: 10 };
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
tooltip={tooltip}
title='Unemployment Rates 1975-2010'>
<Inject services={[StepLineSeries, Tooltip, DateTime]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={data} xName='x' yName='y' name='China' width={2}
type='StepLine' marker={marker}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));export let data = [
{ x: new Date(1975, 0, 1), y: 16, y1: 10, y2: 4.5 },
{ x: new Date(1980, 0, 1), y: 12.5, y1: 7.5, y2: 5 },
{ x: new Date(1985, 0, 1), y: 19, y1: 11, y2: 6.5 },
{ x: new Date(1990, 0, 1), y: 14.4, y1: 7, y2: 4.4 },
{ x: new Date(1995, 0, 1), y: 11.5, y1: 8, y2: 5 },
{ x: new Date(2000, 0, 1), y: 14, y1: 6, y2: 1.5 },
{ x: new Date(2005, 0, 1), y: 10, y1: 3.5, y2: 2.5 },
{ x: new Date(2010, 0, 1), y: 16, y1: 7, y2: 3.7 }
];export let data: Object[] = [
{ x: new Date(1975, 0, 1), y: 16, y1: 10, y2: 4.5 },
{ x: new Date(1980, 0, 1), y: 12.5, y1: 7.5, y2: 5 },
{ x: new Date(1985, 0, 1), y: 19, y1: 11, y2: 6.5 },
{ x: new Date(1990, 0, 1), y: 14.4, y1: 7, y2: 4.4 },
{ x: new Date(1995, 0, 1), y: 11.5, y1: 8, y2: 5 },
{ x: new Date(2000, 0, 1), y: 14, y1: 6, y2: 1.5 },
{ x: new Date(2005, 0, 1), y: 10, y1: 3.5, y2: 2.5 },
{ x: new Date(2010, 0, 1), y: 16, y1: 7, y2: 3.7 }
];Format the tooltip
By default, the tooltip displays the x- and y-values of a data point. Additional information can be shown by specifying a custom format. For example, the format ${series.name} ${point.x} displays the series name along with the x-value of the data point.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, DateTime, Tooltip, DataLabel, StepLineSeries } from '@syncfusion/ej2-react-charts';
import { data } from './datasource';
function App() {
const primaryxAxis = { valueType: 'DateTime' };
const tooltip = {
enable: true, header: 'Unemployment',
format: '<b>${point.x} : ${point.y}</b>'
};
const marker = { visible: true, width: 10, height: 10 };
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} tooltip={tooltip} title='Unemployment Rates 1975-2010'>
<Inject services={[StepLineSeries, Legend, Tooltip, DataLabel, DateTime]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={data} xName='x' yName='y' name='China' width={2} type='StepLine' marker={marker}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));import * as React from "react";
import * as ReactDOM from "react-dom";
import { AxisModel, ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject,TooltipSettingsModel,
Legend, DateTime, Tooltip, DataLabel, StepLineSeries}
from'@syncfusion/ej2-react-charts';
import { data } from './datasource';
function App() {
const primaryxAxis: AxisModel = { valueType: 'DateTime' };
const tooltip: TooltipSettingsModel = {
enable: true, header: 'Unemployment',
format: '<b>${point.x} : ${point.y}</b>'
};
const marker = { visible: true, width: 10, height: 10 };
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
tooltip={tooltip}
title='Unemployment Rates 1975-2010'>
<Inject services={[StepLineSeries, Legend, Tooltip, DataLabel, DateTime]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={data} xName='x' yName='y' name='China' width={2}
type='StepLine' marker={marker}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));export let data = [
{ x: new Date(1975, 0, 1), y: 16, y1: 10, y2: 4.5 },
{ x: new Date(1980, 0, 1), y: 12.5, y1: 7.5, y2: 5 },
{ x: new Date(1985, 0, 1), y: 19, y1: 11, y2: 6.5 },
{ x: new Date(1990, 0, 1), y: 14.4, y1: 7, y2: 4.4 },
{ x: new Date(1995, 0, 1), y: 11.5, y1: 8, y2: 5 },
{ x: new Date(2000, 0, 1), y: 14, y1: 6, y2: 1.5 },
{ x: new Date(2005, 0, 1), y: 10, y1: 3.5, y2: 2.5 },
{ x: new Date(2010, 0, 1), y: 16, y1: 7, y2: 3.7 }
];export let data: Object[] = [
{ x: new Date(1975, 0, 1), y: 16, y1: 10, y2: 4.5 },
{ x: new Date(1980, 0, 1), y: 12.5, y1: 7.5, y2: 5 },
{ x: new Date(1985, 0, 1), y: 19, y1: 11, y2: 6.5 },
{ x: new Date(1990, 0, 1), y: 14.4, y1: 7, y2: 4.4 },
{ x: new Date(1995, 0, 1), y: 11.5, y1: 8, y2: 5 },
{ x: new Date(2000, 0, 1), y: 14, y1: 6, y2: 1.5 },
{ x: new Date(2005, 0, 1), y: 10, y1: 3.5, y2: 2.5 },
{ x: new Date(2010, 0, 1), y: 16, y1: 7, y2: 3.7 }
];Individual series format
Each series tooltip can be formatted separately by using the series tooltipFormat property.
Note: When the series
tooltipFormatproperty is specified, the tooltip for that series is displayed in the defined format. Otherwise, the global tooltip format is applied.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, Category, Tooltip, DataLabel, SplineSeries } from '@syncfusion/ej2-react-charts';
import { data1, data2, data3 } from './datasource';
function App() {
const primaryxAxis = { valueType: 'Category' };
const tooltip = {
enable: true, header: 'Unemployment',
format: '<b>${point.x} : ${point.y}</b>'
};
const marker = { visible: true, width: 10, height: 10 };
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} tooltip={tooltip} title='Unemployment Rates 1975-2010'>
<Inject services={[SplineSeries, Legend, Tooltip, DataLabel, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={data1} xName='x' yName='y' name='Max Temp' width={2} type='Spline' marker={marker} tooltipFormat='${point.x}'>
</SeriesDirective>
<SeriesDirective dataSource={data2} xName='x' yName='y' name='Avg Temp' width={2} type='Spline' marker={marker} tooltipFormat='${point.y}'>
</SeriesDirective>
<SeriesDirective dataSource={data3} xName='x' yName='y' name='Min Temp' width={2} type='Spline' marker={marker}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));import * as React from "react";
import * as ReactDOM from "react-dom";
import { AxisModel, ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject,TooltipSettingsModel, Legend, Category, Tooltip, DataLabel, SplineSeries}
from'@syncfusion/ej2-react-charts';
import { data1, data2, data3 } from './datasource';
function App() {
const primaryxAxis: AxisModel = { valueType: 'Category' };
const tooltip: TooltipSettingsModel = {
enable: true, header: 'Unemployment',
format: '<b>${point.x} : ${point.y}</b>'
};
const marker = { visible: true, width: 10, height: 10 };
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
tooltip={tooltip}
title='Unemployment Rates 1975-2010'>
<Inject services={[SplineSeries, Legend, Tooltip, DataLabel, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={data1} xName='x' yName='y' name='Max Temp' width={2}
type='Spline' marker={marker} tooltipFormat='${point.x}'>
</SeriesDirective>
<SeriesDirective dataSource={data2} xName='x' yName='y' name='Avg Temp' width={2}
type='Spline' marker={marker} tooltipFormat='${point.y}'>
</SeriesDirective>
<SeriesDirective dataSource={data3} xName='x' yName='y' name='Min Temp' width={2}
type='Spline' marker={marker}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));export let data1 = [
{ x: 'Sun', y: 15 },
{ x: 'Mon', y: 22 },
{ x: 'Tue', y: 32 },
{ x: 'Wed', y: 31 },
{ x: 'Thu', y: 29 },
{ x: 'Fri', y: 24 },
{ x: 'Sat', y: 18 }
];
export let data2 = [
{ x: 'Sun', y: 10 },
{ x: 'Mon', y: 18 },
{ x: 'Tue', y: 28 },
{ x: 'Wed', y: 28 },
{ x: 'Thu', y: 26 },
{ x: 'Fri', y: 20 },
{ x: 'Sat', y: 15 }
];
export let data3 = [
{ x: 'Sun', y: 2 },
{ x: 'Mon', y: 12 },
{ x: 'Tue', y: 22 },
{ x: 'Wed', y: 23 },
{ x: 'Thu', y: 19 },
{ x: 'Fri', y: 13 },
{ x: 'Sat', y: 8 }
];export let data1: Object[] = [
{ x: 'Sun', y: 15 },
{ x: 'Mon', y: 22 },
{ x: 'Tue', y: 32 },
{ x: 'Wed', y: 31 },
{ x: 'Thu', y: 29 },
{ x: 'Fri', y: 24 },
{ x: 'Sat', y: 18 }
];
export let data2: Object[] = [
{ x: 'Sun', y: 10 },
{ x: 'Mon', y: 18 },
{ x: 'Tue', y: 28 },
{ x: 'Wed', y: 28 },
{ x: 'Thu', y: 26 },
{ x: 'Fri', y: 20 },
{ x: 'Sat', y: 15 }
];
export let data3: Object[] = [
{ x: 'Sun', y: 2 },
{ x: 'Mon', y: 12 },
{ x: 'Tue', y: 22 },
{ x: 'Wed', y: 23 },
{ x: 'Thu', y: 19 },
{ x: 'Fri', y: 13 },
{ x: 'Sat', y: 8 }
];Tooltip template
Custom HTML content can be rendered in the tooltip by using the template property. The ${x} and ${y} placeholders can be used within the template to display the x- and y-values of the corresponding data point.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, DateTime, Tooltip, DataLabel, StepLineSeries } from '@syncfusion/ej2-react-charts';
import { data } from './datasource';
function App() {
const primaryxAxis = { valueType: 'DateTime' };
const template = chartTemplate;
const tooltip = {
enable: true,
template: template
};
function chartTemplate(args) {
return (<div id="templateWrap">
<table style={{ width: '100%', margin: '5px', border: '1px solid black', backgroundColor: '#00FFFF' }}>
<tbody><tr><th colSpan={2}>Unemployment</th></tr>
<tr><td>{args.x}</td><td>:</td><td>{args.y}</td></tr>
</tbody>
</table>
</div>);
}
const marker = { visible: true, width: 10, height: 10 };
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} tooltip={tooltip} title='Unemployment Rates 1975-2010'>
<Inject services={[StepLineSeries, Legend, Tooltip, DataLabel, DateTime]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={data} xName='x' yName='y' name='China' width={2} type='StepLine' marker={marker}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));import * as React from "react";
import * as ReactDOM from "react-dom";
import { AxisModel, ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject,TooltipSettingsModel,
Legend, DateTime, Tooltip, DataLabel, StepLineSeries}
from'@syncfusion/ej2-react-charts';
import { data } from './datasource';
function App() {
const primaryxAxis: AxisModel = { valueType: 'DateTime' };
const template:any = chartTemplate;
const tooltip: TooltipSettingsModel = {
enable: true,
template: template
};
function chartTemplate(args:any){
return (<div id="templateWrap">
<table style={{width:'100%',margin: '5px', border: '1px solid black' ,backgroundColor:'#00FFFF'}}>
<tbody><tr><th colSpan={2}>Unemployment</th></tr>
<tr><td>{args.x}</td><td>:</td><td>{args.y}</td></tr>
</tbody>
</table>
</div>);
}
const marker = { visible: true, width: 10, height: 10 };
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
tooltip={tooltip}
title='Unemployment Rates 1975-2010'>
<Inject services={[StepLineSeries, Legend, Tooltip, DataLabel, DateTime]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={data} xName='x' yName='y' name='China' width={2}
type='StepLine' marker={marker}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));export let data = [
{ x: new Date(1975, 0, 1), y: 16, y1: 10, y2: 4.5 },
{ x: new Date(1980, 0, 1), y: 12.5, y1: 7.5, y2: 5 },
{ x: new Date(1985, 0, 1), y: 19, y1: 11, y2: 6.5 },
{ x: new Date(1990, 0, 1), y: 14.4, y1: 7, y2: 4.4 },
{ x: new Date(1995, 0, 1), y: 11.5, y1: 8, y2: 5 },
{ x: new Date(2000, 0, 1), y: 14, y1: 6, y2: 1.5 },
{ x: new Date(2005, 0, 1), y: 10, y1: 3.5, y2: 2.5 },
{ x: new Date(2010, 0, 1), y: 16, y1: 7, y2: 3.7 }
];export let data: Object[] = [
{ x: new Date(1975, 0, 1), y: 16, y1: 10, y2: 4.5 },
{ x: new Date(1980, 0, 1), y: 12.5, y1: 7.5, y2: 5 },
{ x: new Date(1985, 0, 1), y: 19, y1: 11, y2: 6.5 },
{ x: new Date(1990, 0, 1), y: 14.4, y1: 7, y2: 4.4 },
{ x: new Date(1995, 0, 1), y: 11.5, y1: 8, y2: 5 },
{ x: new Date(2000, 0, 1), y: 14, y1: 6, y2: 1.5 },
{ x: new Date(2005, 0, 1), y: 10, y1: 3.5, y2: 2.5 },
{ x: new Date(2010, 0, 1), y: 16, y1: 7, y2: 3.7 }
];Enable highlight
By setting the enableHighlight property to true, all points in the hovered series are highlighted while the remaining points are dimmed. This behavior improves focus and readability during data analysis.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, DateTime, Tooltip, StepLineSeries } from'@syncfusion/ej2-react-charts';
import {chartData} from './datasource';
function App() {
const primaryxAxis = {
title: 'Years',
lineStyle: { width: 0 },
labelFormat: 'y',
intervalType: 'Years',
valueType: 'DateTime',
edgeLabelPlacement: 'Shift'
};
const primaryyAxis = {
title: 'Percentage (%)',
minimum: 0,
maximum: 20,
interval: 4,
labelFormat: '{value}%'
};
const tooltip = { enable: true, enableHighlight: true };
const legendSettings = { visible: true };
const marker = { visible: true, width: 10, height: 10 };
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
tooltip={tooltip}
legendSettings={legendSettings}
title='Unemployment Rates 1975-2010'>
<Inject services={[StepLineSeries, Legend, Tooltip, DateTime]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={chartData} xName='x' yName='y' type='StepLine' name='China' width={2} marker={marker}>
</SeriesDirective>
<SeriesDirective dataSource={chartData} xName='x' yName='y1' type='StepLine' name='Australia' width={2} marker={marker}>
</SeriesDirective>
<SeriesDirective dataSource={chartData} xName='x' yName='y2' type='StepLine' name='Japan' width={2} marker={marker}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, AxisModel, TooltipSettingsModel, LegendSettingsModel, Legend, DateTime, Tooltip, StepLineSeries } from'@syncfusion/ej2-react-charts';
import {chartData} from './datasource';
function App() {
const primaryxAxis: AxisModel = {
title: 'Years',
lineStyle: { width: 0 },
labelFormat: 'y',
intervalType: 'Years',
valueType: 'DateTime',
edgeLabelPlacement: 'Shift'
};
const primaryyAxis: AxisModel = {
title: 'Percentage (%)',
minimum: 0,
maximum: 20,
interval: 4,
labelFormat: '{value}%'
};
const tooltip: TooltipSettingsModel = { enable: true, enableHighlight: true };
const legendSettings: LegendSettingsModel = { visible: true };
const marker = { visible: true, width: 10, height: 10 };
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
tooltip={tooltip}
legendSettings={legendSettings}
title='Unemployment Rates 1975-2010'>
<Inject services={[StepLineSeries, Legend, Tooltip, DateTime]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={chartData} xName='x' yName='y' type='StepLine' name='China' width={2} marker={marker}>
</SeriesDirective>
<SeriesDirective dataSource={chartData} xName='x' yName='y1' type='StepLine' name='Australia' width={2} marker={marker}>
</SeriesDirective>
<SeriesDirective dataSource={chartData} xName='x' yName='y2' type='StepLine' name='Japan' width={2} marker={marker}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));export let chartData = [
{ x: new Date(1975, 0, 1), y: 16, y1: 10, y2: 4.5 },
{ x: new Date(1980, 0, 1), y: 12.5, y1: 7.5, y2: 5 },
{ x: new Date(1985, 0, 1), y: 19, y1: 11, y2: 6.5 },
{ x: new Date(1990, 0, 1), y: 14.4, y1: 7, y2: 4.4 },
{ x: new Date(1995, 0, 1), y: 11.5, y1: 8, y2: 5 },
{ x: new Date(2000, 0, 1), y: 14, y1: 6, y2: 1.5 },
{ x: new Date(2005, 0, 1), y: 10, y1: 3.5, y2: 2.5 },
{ x: new Date(2010, 0, 1), y: 16, y1: 7, y2: 3.7 }
];export let chartData: Object[] = [
{ x: new Date(1975, 0, 1), y: 16, y1: 10, y2: 4.5 },
{ x: new Date(1980, 0, 1), y: 12.5, y1: 7.5, y2: 5 },
{ x: new Date(1985, 0, 1), y: 19, y1: 11, y2: 6.5 },
{ x: new Date(1990, 0, 1), y: 14.4, y1: 7, y2: 4.4 },
{ x: new Date(1995, 0, 1), y: 11.5, y1: 8, y2: 5 },
{ x: new Date(2000, 0, 1), y: 14, y1: 6, y2: 1.5 },
{ x: new Date(2005, 0, 1), y: 10, y1: 3.5, y2: 2.5 },
{ x: new Date(2010, 0, 1), y: 16, y1: 7, y2: 3.7 }
];Tooltip mapping name
By default, the tooltip displays only the x- and y-values of a data point. Additional information from the data source can be shown by using the tooltipMappingName property of the series. Use the ${point.tooltip} placeholder in the tooltip format to display the mapped value.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Category, Legend, DateTime, Tooltip, DataLabel, ColumnSeries } from '@syncfusion/ej2-react-charts';
import { chartData } from './datasource';
function App() {
const primaryxAxis = { valueType: 'DateTime' };
const tooltip = { enable: true, format: '${point.tooltip}' };
const legendSettings = { visible: false };
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} tooltip={tooltip} legendSettings={legendSettings} title='Internet Users in Million – 2016'>
<Inject services={[ColumnSeries, Legend, Tooltip, DataLabel, DateTime, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={chartData} xName='x' yName='y' type='Column' tooltipMappingName='country'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));import * as React from "react";
import * as ReactDOM from "react-dom";
import { AxisModel, ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject,TooltipSettingsModel,LegendSettingsModel,Category,
Legend, DateTime, Tooltip, DataLabel, ColumnSeries}
from'@syncfusion/ej2-react-charts';
import {chartData} from './datasource';
function App() {
const primaryxAxis: AxisModel = { valueType: 'DateTime' };
const tooltip: TooltipSettingsModel = {enable: true, format: '${point.tooltip}'};
const legendSettings: LegendSettingsModel = { visible: false};
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
tooltip={tooltip}
legendSettings={legendSettings}
title='Internet Users in Million – 2016'>
<Inject services={[ColumnSeries, Legend, Tooltip, DataLabel, DateTime, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={chartData} xName='x' yName='y'
type='Column' tooltipMappingName='country'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));export let chartData = [
{ 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 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'}
];export let chartData: Object[] = [
{ 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 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'}
];Customize the appearance of tooltip
The appearance of the tooltip can be customized by using the following properties:
-
fillto set the background color -
borderto configure the tooltip border -
textStyleto customize the tooltip text style
ThehighlightColorproperty is used to change the color of a data point when it is highlighted during tooltip interaction.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, DateTime, Tooltip, DataLabel, StepLineSeries } from '@syncfusion/ej2-react-charts';
import { data } from './datasource';
function App() {
const primaryxAxis = { valueType: 'DateTime' };
const tooltip = {
enable: true, format: '${series.name} ${point.x} : ${point.y}',
fill: '#7bb4eb', border: {
width: 2,
color: 'grey'
}
};
const marker = { visible: true, width: 10, height: 10 };
const titlestyle = {
fontFamily: "Arial", fontStyle: 'italic', fontWeight: 'regular',
color: "#E27F2D", size: '23px'
};
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} tooltip={tooltip} title='Unemployment Rates 1975-2010' highlightColor='red' titleStyle={titlestyle}>
<Inject services={[StepLineSeries, Legend, Tooltip, DataLabel, DateTime]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={data} xName='x' yName='y' name='China' width={2} type='StepLine' marker={marker}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));import * as React from "react";
import * as ReactDOM from "react-dom";
import { AxisModel, ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject,TooltipSettingsModel,
Legend, DateTime, Tooltip, DataLabel, StepLineSeries}
from'@syncfusion/ej2-react-charts';
import { data } from './datasource';
function App() {
const primaryxAxis: AxisModel = { valueType: 'DateTime' };
const tooltip: TooltipSettingsModel = {
enable: true, format: '${series.name} ${point.x} : ${point.y}',
fill: '#7bb4eb', border: {
width: 2,
color: 'grey'
}
};
const marker = { visible: true, width: 10, height: 10 };
const titlestyle = {
fontFamily: "Arial", fontStyle: 'italic', fontWeight: 'regular',
color: "#E27F2D", size: '23px'
};
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
tooltip={tooltip}
title='Unemployment Rates 1975-2010'
highlightColor='red'
titleStyle={titlestyle}>
<Inject services={[StepLineSeries, Legend, Tooltip, DataLabel, DateTime]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={data} xName='x' yName='y' name='China' width={2}
type='StepLine' marker={marker}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));export let data = [
{ x: new Date(1975, 0, 1), y: 16, y1: 10, y2: 4.5 },
{ x: new Date(1980, 0, 1), y: 12.5, y1: 7.5, y2: 5 },
{ x: new Date(1985, 0, 1), y: 19, y1: 11, y2: 6.5 },
{ x: new Date(1990, 0, 1), y: 14.4, y1: 7, y2: 4.4 },
{ x: new Date(1995, 0, 1), y: 11.5, y1: 8, y2: 5 },
{ x: new Date(2000, 0, 1), y: 14, y1: 6, y2: 1.5 },
{ x: new Date(2005, 0, 1), y: 10, y1: 3.5, y2: 2.5 },
{ x: new Date(2010, 0, 1), y: 16, y1: 7, y2: 3.7 }
];export let data: Object[] = [
{ x: new Date(1975, 0, 1), y: 16, y1: 10, y2: 4.5 },
{ x: new Date(1980, 0, 1), y: 12.5, y1: 7.5, y2: 5 },
{ x: new Date(1985, 0, 1), y: 19, y1: 11, y2: 6.5 },
{ x: new Date(1990, 0, 1), y: 14.4, y1: 7, y2: 4.4 },
{ x: new Date(1995, 0, 1), y: 11.5, y1: 8, y2: 5 },
{ x: new Date(2000, 0, 1), y: 14, y1: 6, y2: 1.5 },
{ x: new Date(2005, 0, 1), y: 10, y1: 3.5, y2: 2.5 },
{ x: new Date(2010, 0, 1), y: 16, y1: 7, y2: 3.7 }
];Closest tooltip
The showNearestTooltip property displays the tooltip for the data point nearest to the pointer, even when the pointer is not directly positioned over the point.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, DateTime, Tooltip, StepLineSeries } from'@syncfusion/ej2-react-charts';
import {chartData} from './datasource';
function App() {
const primaryxAxis = {
title: 'Years',
lineStyle: { width: 0 },
labelFormat: 'y',
intervalType: 'Years',
valueType: 'DateTime',
edgeLabelPlacement: 'Shift'
};
const primaryyAxis = {
title: 'Percentage (%)',
minimum: 0,
maximum: 20,
interval: 4,
labelFormat: '{value}%'
};
const tooltip = { enable: true, enableHighlight: true, showNearestTooltip: true };
const legendSettings = { visible: true };
const marker = { visible: true, width: 10, height: 10 };
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
tooltip={tooltip}
legendSettings={legendSettings}
title='Unemployment Rates 1975-2010'>
<Inject services={[StepLineSeries, Legend, Tooltip, DateTime]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={chartData} xName='x' yName='y' type='StepLine' name='China' width={2} marker={marker}>
</SeriesDirective>
<SeriesDirective dataSource={chartData} xName='x' yName='y1' type='StepLine' name='Australia' width={2} marker={marker}>
</SeriesDirective>
<SeriesDirective dataSource={chartData} xName='x' yName='y2' type='StepLine' name='Japan' width={2} marker={marker}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, AxisModel, TooltipSettingsModel, LegendSettingsModel, Legend, DateTime, Tooltip, StepLineSeries } from'@syncfusion/ej2-react-charts';
import {chartData} from './datasource';
function App() {
const primaryxAxis: AxisModel = {
title: 'Years',
lineStyle: { width: 0 },
labelFormat: 'y',
intervalType: 'Years',
valueType: 'DateTime',
edgeLabelPlacement: 'Shift'
};
const primaryyAxis: AxisModel = {
title: 'Percentage (%)',
minimum: 0,
maximum: 20,
interval: 4,
labelFormat: '{value}%'
};
const tooltip: TooltipSettingsModel = { enable: true, enableHighlight: true, showNearestTooltip: true };
const legendSettings: LegendSettingsModel = { visible: true };
const marker = { visible: true, width: 10, height: 10 };
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
tooltip={tooltip}
legendSettings={legendSettings}
title='Unemployment Rates 1975-2010'>
<Inject services={[StepLineSeries, Legend, Tooltip, DateTime]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={chartData} xName='x' yName='y' type='StepLine' name='China' width={2} marker={marker}>
</SeriesDirective>
<SeriesDirective dataSource={chartData} xName='x' yName='y1' type='StepLine' name='Australia' width={2} marker={marker}>
</SeriesDirective>
<SeriesDirective dataSource={chartData} xName='x' yName='y2' type='StepLine' name='Japan' width={2} marker={marker}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));export let chartData = [
{ x: new Date(1975, 0, 1), y: 16, y1: 10, y2: 4.5 },
{ x: new Date(1980, 0, 1), y: 12.5, y1: 7.5, y2: 5 },
{ x: new Date(1985, 0, 1), y: 19, y1: 11, y2: 6.5 },
{ x: new Date(1990, 0, 1), y: 14.4, y1: 7, y2: 4.4 },
{ x: new Date(1995, 0, 1), y: 11.5, y1: 8, y2: 5 },
{ x: new Date(2000, 0, 1), y: 14, y1: 6, y2: 1.5 },
{ x: new Date(2005, 0, 1), y: 10, y1: 3.5, y2: 2.5 },
{ x: new Date(2010, 0, 1), y: 16, y1: 7, y2: 3.7 }
];export let chartData: Object[] = [
{ x: new Date(1975, 0, 1), y: 16, y1: 10, y2: 4.5 },
{ x: new Date(1980, 0, 1), y: 12.5, y1: 7.5, y2: 5 },
{ x: new Date(1985, 0, 1), y: 19, y1: 11, y2: 6.5 },
{ x: new Date(1990, 0, 1), y: 14.4, y1: 7, y2: 4.4 },
{ x: new Date(1995, 0, 1), y: 11.5, y1: 8, y2: 5 },
{ x: new Date(2000, 0, 1), y: 14, y1: 6, y2: 1.5 },
{ x: new Date(2005, 0, 1), y: 10, y1: 3.5, y2: 2.5 },
{ x: new Date(2010, 0, 1), y: 16, y1: 7, y2: 3.7 }
];