Skip to content


You can register handlers for various events. There are pointer events (click, pointermove), animation events (begin, update, complete), and rendering events that are called before rendering the chart elements. Handlers can be registered/unregistered with the on, off method pair.


Currently on method only accept handler's JavaScript expression as string. The event can be accessed via the event object, see the examples below.

We are registering a handler for the click event which will show an alert block with information about the clicked chart element.

Info - How to setup Chart

import pandas as pd
from ipyvizzu import Chart, Data, Config

df = pd.read_csv(
data = Data()

chart = Chart()

            "channels": {
                "y": {"set": ["Popularity", "Kinds"]},
                "x": {"set": ["Genres"]},
                "color": {"set": ["Kinds"]},
                "label": {"set": ["Popularity"]},

click_handler = "alert(JSON.stringify(;"

click = chart.on("click", click_handler)

Unregistering the previously registered handler.

Here we override the axis label color for Jazz to red and all others to gray.

label_draw_handler = (
    "event.renderingContext.fillStyle ="
    + " ( === 'Jazz') ? 'red' : 'gray';"

label_draw = chart.on("plot-axis-label-draw", label_draw_handler)

Unregistering the previously registered handler.

The default behaviour of all events can be blocked by calling the event's preventDefault method. Here we block the drawing of the Vizzu logo in the bottom right corner of the chart.

logo_draw_handler = "event.preventDefault();"

logo_draw = chart.on("logo-draw", logo_draw_handler)

Unregistering the previously registered handler.

You can also add a background image to the chart using the preventDefault method.

bgimage_draw_handler = """
if (!window.bgImage) {
    window.bgImage = new Image();
    /* base64 converted image */
    window.bgImage.src = 'data:image/gif;base64,R0lGODlhAwACAPIAAJLf6q/i7M/r8un0+PT6+/n8/QAAAAAAACH5BAQAAAAALAAAAAADAAIAAAMEWBMkkAA7';
event.renderingContext.drawImage(window.bgImage, 0, 0,
    event.detail.rect.size.x, event.detail.rect.size.y);

bgimage_draw = chart.on("background-draw", bgimage_draw_handler)

chart.animate(Config({"title": "Add background image"}))


Place the chart.on call before the chart.animate call from where you want to replace the background image.

Unregistering the previously registered handler.