Skip to content

Configuring the zoom out button

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";
Open in CodePen

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;
Open in CodePen

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;

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");
Open in CodePen

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.

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;

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.width = 15;
zoomImage.height = 15;
zoomImage.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.

Open in CodePen