When XYChart is zoomed in, a small round button appears in the corner to indicate that only partial data is show, and to provide means to zoom back out. This tutorial will show how you can configure, or outright disable this control.
The zoom out button is accessible via chart’s zoomOutButton property. It’s an object of type Button, and we are going to be using it in order to configure it.
By default, the zoom out button is positioned in the upper right corner of the plotContainer of the chart.
To reposition it horizontally, we can use its align property, and to move vertically - valign.
The below code will place the button in the lower-right corner:
chart . zoomOutButton . align = " left " ;
chart . zoomOutButton . valign = " bottom " ;
chart . zoomOutButton . align = " left " ;
chart . zoomOutButton . valign = " bottom " ;
Run * ---------------------------------------
* This demo was created using amCharts 4.
* For more information visit:
* https://www.amcharts.com/
* Documentation is available at:
* https://www.amcharts.com/docs/v4/
* ---------------------------------------
am4core . useTheme ( am4themes_animated );
var chart = am4core . create ( " chartdiv " , am4charts . XYChart );
date: new Date ( 2018 , 0 , 1 ),
date: new Date ( 2018 , 0 , 2 ),
date: new Date ( 2018 , 0 , 3 ),
date: new Date ( 2018 , 0 , 4 ),
date: new Date ( 2018 , 0 , 5 ),
date: new Date ( 2018 , 0 , 6 ),
date: new Date ( 2018 , 0 , 7 ),
var dateAxis = chart . xAxes . push ( new am4charts . DateAxis ());
dateAxis . renderer . grid . template . location = 0 ;
//dateAxis.renderer.minGridDistance = 30;
var valueAxis = chart . yAxes . push ( new am4charts . ValueAxis ());
function createSeries ( field , name ) {
var series = chart . series . push ( new am4charts . LineSeries ());
series . dataFields . valueY = field ;
series . dataFields . dateX = " date " ;
series . tooltipText = " {dateX}: [b]{valueY}[/] " ;
var bullet = series . bullets . push ( new am4charts . CircleBullet ());
bullet . circle . stroke = am4core . color ( " #fff " );
bullet . circle . strokeWidth = 2 ;
createSeries ( " value " , " Series #1 " );
createSeries ( " value2 " , " Series #2 " );
createSeries ( " value3 " , " Series #3 " );
chart . legend = new am4charts . Legend ();
chart . cursor = new am4charts . XYCursor ();
chart . events . on ( " ready " , function () {
dateAxis . zoomToDates ( new Date ( 2018 , 0 , 3 ) , new Date ( 2018 , 0 , 6 ));
chart . zoomOutButton . align = " left " ;
chart . zoomOutButton . valign = " bottom " ;
chart . zoomOutButton . marginLeft = 10 ;
chart . zoomOutButton . marginBottom = 10 ;
< div id = " chartdiv " ></ div >
-apple-system , BlinkMacSystemFont, " Segoe UI " , Roboto, Helvetica , Arial , sans-serif ,
" Apple Color Emoji " , " Segoe UI Emoji " , " Segoe UI Symbol " ;
Configuring Zoom Out button configuring-zoom-out-button
If you’d rather move the zoom out button outside plot area, you can simply use its parent property to move it somewhere else, e.g. to tooltipContainer which spans whole area of the chart:
chart . zoomOutButton . parent = chart . tooltipContainer ;
chart . zoomOutButton . parent = chart . tooltipContainer ;
this.parent = this.baseSprite.tooltipContainer;
Run * ---------------------------------------
* This demo was created using amCharts 4.
* For more information visit:
* https://www.amcharts.com/
* Documentation is available at:
* https://www.amcharts.com/docs/v4/
* ---------------------------------------
am4core . useTheme ( am4themes_animated );
var chart = am4core . create ( " chartdiv " , am4charts . XYChart );
date: new Date ( 2018 , 0 , 1 ),
date: new Date ( 2018 , 0 , 2 ),
date: new Date ( 2018 , 0 , 3 ),
date: new Date ( 2018 , 0 , 4 ),
date: new Date ( 2018 , 0 , 5 ),
date: new Date ( 2018 , 0 , 6 ),
date: new Date ( 2018 , 0 , 7 ),
var dateAxis = chart . xAxes . push ( new am4charts . DateAxis ());
dateAxis . renderer . grid . template . location = 0 ;
//dateAxis.renderer.minGridDistance = 30;
var valueAxis = chart . yAxes . push ( new am4charts . ValueAxis ());
function createSeries ( field , name ) {
var series = chart . series . push ( new am4charts . LineSeries ());
series . dataFields . valueY = field ;
series . dataFields . dateX = " date " ;
series . tooltipText = " {dateX}: [b]{valueY}[/] " ;
var bullet = series . bullets . push ( new am4charts . CircleBullet ());
bullet . circle . stroke = am4core . color ( " #fff " );
bullet . circle . strokeWidth = 2 ;
createSeries ( " value " , " Series #1 " );
createSeries ( " value2 " , " Series #2 " );
createSeries ( " value3 " , " Series #3 " );
chart . legend = new am4charts . Legend ();
chart . cursor = new am4charts . XYCursor ();
chart . events . on ( " ready " , function () {
dateAxis . zoomToDates ( new Date ( 2018 , 0 , 3 ) , new Date ( 2018 , 0 , 6 ));
chart . zoomOutButton . parent = chart . tooltipContainer ;
< div id = " chartdiv " ></ div >
-apple-system , BlinkMacSystemFont, " Segoe UI " , Roboto, Helvetica , Arial , sans-serif ,
" Apple Color Emoji " , " Segoe UI Emoji " , " Segoe UI Symbol " ;
Configuring Zoom Out button configuring-zoom-out-button-2
In some case you might not want the zoom out button appearing at all. Maybe you have a scrollbar, or some external controls.
In such case you can simply set button’s disabled property to true:
chart . zoomOutButton . disabled = true ;
chart . zoomOutButton . disabled = true ;
As we already mentioned, zoom out button is an object of type Button.
This means we can use its properties to configure it any way we need.
Let’s make it not round by reducing corner radius of its background, as well as change colors:
chart . zoomOutButton . background . cornerRadius ( 5 , 5 , 5 , 5 );
chart . zoomOutButton . background . fill = am4core . color ( " #25283D " );
chart . zoomOutButton . icon . stroke = am4core . color ( " #EFD9CE " );
chart . zoomOutButton . icon . strokeWidth = 2 ;
chart . zoomOutButton . background . states . getKey ( " hover " ) . properties . fill = am4core . color ( " #606271 " );
chart . zoomOutButton . background . cornerRadius ( 5 , 5 , 5 , 5 );
chart . zoomOutButton . background . fill = am4core . color ( " #25283D " );
chart . zoomOutButton . icon . stroke = am4core . color ( " #EFD9CE " );
chart . zoomOutButton . icon . strokeWidth = 2 ;
chart . zoomOutButton . background . states . getKey ( " hover " ) . properties . fill = am4core . color ( " #606271 " );
"cornerRadiusTopLeft" : 5 ,
"cornerRadiusTopRight" : 5 ,
"cornerRadiusBottomRight" : 5 ,
"cornerRadiusBottomLeft" : 5 ,
Run * ---------------------------------------
* This demo was created using amCharts 4.
* For more information visit:
* https://www.amcharts.com/
* Documentation is available at:
* https://www.amcharts.com/docs/v4/
* ---------------------------------------
am4core . useTheme ( am4themes_animated );
var chart = am4core . create ( " chartdiv " , am4charts . XYChart );
date: new Date ( 2018 , 0 , 1 ),
date: new Date ( 2018 , 0 , 2 ),
date: new Date ( 2018 , 0 , 3 ),
date: new Date ( 2018 , 0 , 4 ),
date: new Date ( 2018 , 0 , 5 ),
date: new Date ( 2018 , 0 , 6 ),
date: new Date ( 2018 , 0 , 7 ),
var dateAxis = chart . xAxes . push ( new am4charts . DateAxis ());
dateAxis . renderer . grid . template . location = 0 ;
//dateAxis.renderer.minGridDistance = 30;
var valueAxis = chart . yAxes . push ( new am4charts . ValueAxis ());
function createSeries ( field , name ) {
var series = chart . series . push ( new am4charts . LineSeries ());
series . dataFields . valueY = field ;
series . dataFields . dateX = " date " ;
series . tooltipText = " {dateX}: [b]{valueY}[/] " ;
var bullet = series . bullets . push ( new am4charts . CircleBullet ());
bullet . circle . stroke = am4core . color ( " #fff " );
bullet . circle . strokeWidth = 2 ;
createSeries ( " value " , " Series #1 " );
createSeries ( " value2 " , " Series #2 " );
createSeries ( " value3 " , " Series #3 " );
chart . legend = new am4charts . Legend ();
chart . cursor = new am4charts . XYCursor ();
chart . events . on ( " ready " , function () {
dateAxis . zoomToDates ( new Date ( 2018 , 0 , 3 ) , new Date ( 2018 , 0 , 6 ));
chart . zoomOutButton . background . cornerRadius ( 5 , 5 , 5 , 5 );
chart . zoomOutButton . background . fill = am4core . color ( " #25283D " );
chart . zoomOutButton . icon . stroke = am4core . color ( " #EFD9CE " );
chart . zoomOutButton . icon . strokeWidth = 2 ;
chart . zoomOutButton . background . states . getKey ( " hover " ) . properties . fill = am4core . color ( " #606271 " );
< div id = " chartdiv " ></ div >
-apple-system , BlinkMacSystemFont, " Segoe UI " , Roboto, Helvetica , Arial , sans-serif ,
" Apple Color Emoji " , " Segoe UI Emoji " , " Segoe UI Symbol " ;
Configuring Zoom Out button configuring-zoom-out-button-3
Let’s go one step further and replace a custom minus image which appears on zoom out button with something more custom. Say a magnifying class.
Default look Desired look
There are a few steps to it. Let’s walk through all of them.
A default icon resides in button’s icon property.
To get rid of it, we’ll simply need to to disable it:
chart . zoomOutButton . icon . disabled = true ;
chart . zoomOutButton . icon . disabled = true ;
Now that our button is empty, let’s an image to it.
We do that by creating a child element of an Image type:
let zoomImage = chart . zoomOutButton . createChild (am4core . Image );
zoomImage . href = " /path/to/zoomImage.png " ;
zoomImage . interactionsEnabled = false ;
var zoomImage = chart . zoomOutButton . createChild ( am4core . Image );
zoomImage . href = " /path/to/zoomImage.png " ;
zoomImage . interactionsEnabled = false ;
"href" : " /path/to/zoomImage.png " ,
"interactionsEnabled" : false
Besides creating an instance of Image we also need to at least set its width and height, as well as href which points to the actual image.
Run * ---------------------------------------
* This demo was created using amCharts 4.
* For more information visit:
* https://www.amcharts.com/
* Documentation is available at:
* https://www.amcharts.com/docs/v4/
* ---------------------------------------
am4core . useTheme ( am4themes_animated );
var chart = am4core . create ( " chartdiv " , am4charts . XYChart );
date: new Date ( 2018 , 0 , 1 ),
date: new Date ( 2018 , 0 , 2 ),
date: new Date ( 2018 , 0 , 3 ),
date: new Date ( 2018 , 0 , 4 ),
date: new Date ( 2018 , 0 , 5 ),
date: new Date ( 2018 , 0 , 6 ),
date: new Date ( 2018 , 0 , 7 ),
var dateAxis = chart . xAxes . push ( new am4charts . DateAxis ());
dateAxis . renderer . grid . template . location = 0 ;
dateAxis . renderer . minGridDistance = 30 ;
chart . events . on ( " ready " , function () {
var valueAxis = chart . yAxes . push ( new am4charts . ValueAxis ());
function createSeries ( field , name ) {
var series = chart . series . push ( new am4charts . LineSeries ());
series . dataFields . valueY = field ;
series . dataFields . dateX = " date " ;
series . tooltipText = " {dateX}: [b]{valueY}[/] " ;
var bullet = series . bullets . push ( new am4charts . CircleBullet ());
bullet . circle . stroke = am4core . color ( " #fff " );
bullet . circle . strokeWidth = 2 ;
createSeries ( " value " , " Series #1 " );
createSeries ( " value2 " , " Series #2 " );
createSeries ( " value3 " , " Series #3 " );
chart . legend = new am4charts . Legend ();
chart . cursor = new am4charts . XYCursor ();
chart . scrollbarX = new am4core . Scrollbar ();
chart . zoomOutButton . icon . disabled = true ;
var zoomImage = chart . zoomOutButton . createChild ( am4core .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iw1NiwzNy43OTEsNTYsNDBMNTYsNDB6Ii8+PC9zdmc+ " ;
zoomImage . interactionsEnabled = false ;
< div id = " chartdiv " ></ div >
-apple-system , BlinkMacSystemFont, " Segoe UI " , Roboto, Helvetica , Arial , sans-serif ,
" Apple Color Emoji " , " Segoe UI Emoji " , " Segoe UI Symbol " ;
Using custom image in ZoomOutButton using-custom-image-in-zoomoutbutton