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

Filter in JavaScript

How to use D3.js-based Filters in Plotly.js.


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 subject = ['Moe','Larry','Curly','Moe','Larry','Curly','Moe','Larry','Curly','Moe','Larry','Curly']
var score = [1,6,2,8,2,9,4,5,1,5,2,8]

var data = [{
  type: 'scatter',
  x: subject,
  y: score,
  mode: 'markers',
  transforms: [{
    type: 'filter',
    target: 'y',
    operation: '>',
    value: 4
  }]
}]

var layout = {
	title: 'Filter Scores > 4'
}

Plotly.newPlot('myDiv', data, layout)