✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.

Zoom Events in JavaScript

How to bind callback functions to zoom events in D3.js-based JavaScript charts.

Building full-stack apps and dashboards with Plotly.js?
Increase development speed by 2x-10x with Dash. 🏃

New to Plotly?

Plotly is a free and open-source graphing library for JavaScript. We recommend you read our Getting Started guide for the latest installation or upgrade instructions, then move on to our Plotly Fundamentals tutorials or dive straight in to some Basic Charts tutorials.

var graphDiv = document.getElementById('myDiv');

var N = 40,
    x = d3.range(N),
    y = d3.range(N).map( d3.random.normal() ),
    data = [ { x:x, y:y } ];
    layout = { title:'Click-drag to zoom' };

Plotly.newPlot(graphDiv, data, layout);

        alert( 'ZOOM!' + '\n\n' +
            'Event data:' + '\n' +
             JSON.stringify(eventdata) + '\n\n' +
            'x-axis start:' + eventdata['xaxis.range[0]'] + '\n' +
            'x-axis end:' + eventdata['xaxis.range[1]'] );