🏥 🏭 Working on the COVID-19 response in Canada? Plotly & the Canadian government can help you and your organization. Learn more and get in touch.

Groupby in JavaScript

How to use D3.js-based Group By 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: 'groupby',
    groups: subject,
    styles: [
      {target: 'Moe', value: {marker: {color: 'blue'}}},
      {target: 'Larry', value: {marker: {color: 'red'}}},
      {target: 'Curly', value: {marker: {color: 'black'}}}

Plotly.newPlot('myDiv', data)