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

Get data for current zoomed in view

I have created a scatter plot and i want to get the data of only the current zoomed in view(Not the entire view). How can i do that?

We don’t expose an easy way to do that.

Something like:

var gd = document.getElementById('graph')
var xRange = gd.layout.xaxis.range
var yRange = gd.layout.yaxis.range => {
  var len = Math.min(trace.x.length, trace.y.length)
  var xInside = []
  var yInside = []

  for (var i = 0; i < len; i++) {
    var x = trace.x[i]
    var y = trace.y[i]

    if(x > xRange[0] && x < xRange[1] && y > yRange[0] && y < yRange[1]) {

should do the trick.

Thank you @etienne, it did the trick.

hi, there, i have a doubt, how can we do the same for bar chart like this in the following codepen . is there a way to get the data from current zoom view when x or y contains string values?