Normally, tooltips in charts take square shape to match the content within. This quick tutorial will show how to configure Tooltip object to resemble a round fixed-radius shape.
We’re going to start off with a basic chart that has one line series, a cursor and regular tooltips enabled:
Result JS HTML CSS
Open in: New tab CodePen (opens in a new tab) jsFiddle (opens in a new tab) Run * --------------------------------------------------------
* This demo was created using amCharts V4 preview release.
* V4 is the latest installement in amCharts data viz
* library family, to be released in the first half of
* For more information and documentation visit:
* https://www.amcharts.com/docs/v4/
* --------------------------------------------------------
am4core . useTheme ( am4themes_animated );
var chart = am4core . create ( " chartdiv " , am4charts . XYChart );
var categoryAxis = chart . xAxes . push ( new am4charts . CategoryAxis ());
categoryAxis . dataFields . category = " category " ;
categoryAxis . renderer . grid . template . location = 0 ;
categoryAxis . renderer . minGridDistance = 30 ;
categoryAxis . renderer . grid . template . location = 0.5 ;
categoryAxis . startLocation = 0.3 ;
categoryAxis . endLocation = 0.7 ;
var valueAxis = chart . yAxes . push ( new am4charts . ValueAxis ());
var series = chart . series . push ( new am4charts . LineSeries ());
series . dataFields . valueY = " value " ;
series . dataFields . categoryX = " category " ;
series . tooltipText = " {value} " ;
chart . cursor = new am4charts . XYCursor ();
< div id = " chartdiv " ></ div >
-apple-system , BlinkMacSystemFont, " Segoe UI " , Roboto, Helvetica , Arial , sans-serif ,
" Apple Color Emoji " , " Segoe UI Emoji " , " Segoe UI Symbol " ;
Drop-like tooltip shape (1) drop-like-tooltip-shape-1
As you can see it displays a square, variable width tooltip to the side of the data item currently being hovered:
Regular tooltip
We’re now going to go ahead and give our tooltip a complete makeover.
For that we’re going to take the following steps:
Round the corners for tooltip to the size of our target circle:
series.tooltip.background.cornerRadius = 20
Disable outline so that pointer does not look like it’s cut off from the tooltip body by rounded corners:
series.tooltip.background.strokeOpacity = 0
Change the orientation for the tooltip to vertical:
series.tooltip.pointerOrientation = "vertical"
Set minimum dimensions for the label in our tooltip:
series.tooltip.label.minWidth = 40
series.tooltip.label.minHeight = 40
Align the label text so it’s right in the center:
series.tooltip.label.textAlign = "middle"
series.tooltip.label.textValign = "middle"
Complete code:
series . tooltipText = " {value} " ;
series . tooltip . background . cornerRadius = 20 ;
series . tooltip . background . strokeOpacity = 0 ;
series . tooltip . pointerOrientation = " vertical " ;
series . tooltip . label . minWidth = 40 ;
series . tooltip . label . minHeight = 40 ;
series . tooltip . label . textAlign = " middle " ;
series . tooltip . label . textValign = " middle " ;
series . tooltipText = " {value} " ;
series . tooltip . background . cornerRadius = 20 ;
series . tooltip . background . strokeOpacity = 0 ;
series . tooltip . pointerOrientation = " vertical " ;
series . tooltip . label . minWidth = 40 ;
series . tooltip . label . minHeight = 40 ;
series . tooltip . label . textAlign = " middle " ;
series . tooltip . label . textValign = " middle " ;
"tooltipText" : " {value} " ,
"pointerOrientation" : " vertical " ,
This should result in tooltip looking like this:
Round tooltip
Result JS HTML CSS
Open in: New tab CodePen (opens in a new tab) jsFiddle (opens in a new tab) Run * --------------------------------------------------------
* This demo was created using amCharts V4 preview release.
* V4 is the latest installement in amCharts data viz
* library family, to be released in the first half of
* For more information and documentation visit:
* https://www.amcharts.com/docs/v4/
* --------------------------------------------------------
am4core . useTheme ( am4themes_animated );
var chart = am4core . create ( " chartdiv " , am4charts . XYChart );
var categoryAxis = chart . xAxes . push ( new am4charts . CategoryAxis ());
categoryAxis . dataFields . category = " category " ;
categoryAxis . renderer . grid . template . location = 0 ;
categoryAxis . renderer . minGridDistance = 30 ;
categoryAxis . renderer . grid . template . location = 0.5 ;
categoryAxis . startLocation = 0.3 ;
categoryAxis . endLocation = 0.7 ;
var valueAxis = chart . yAxes . push ( new am4charts . ValueAxis ());
var series = chart . series . push ( new am4charts . LineSeries ());
series . dataFields . valueY = " value " ;
series . dataFields . categoryX = " category " ;
series . tooltipText = " {value} " ;
series . tooltip . background . cornerRadius = 20 ;
series . tooltip . background . strokeOpacity = 0 ;
series . tooltip . pointerOrientation = " vertical " ;
series . tooltip . label . minWidth = 40 ;
series . tooltip . label . minHeight = 40 ;
series . tooltip . label . textAlign = " middle " ;
series . tooltip . label . textValign = " middle " ;
chart . cursor = new am4charts . XYCursor ();
< div id = " chartdiv " ></ div >
-apple-system , BlinkMacSystemFont, " Segoe UI " , Roboto, Helvetica , Arial , sans-serif ,
" Apple Color Emoji " , " Segoe UI Emoji " , " Segoe UI Symbol " ;
Drop-like tooltip shape (2) drop-like-tooltip-shape-2