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

Polar Charts [legacy] in JavaScript

How to graph D3.js-based polar charts in javascript. Seven examples of polar line, polar scatter and polar area charts.


Building AI apps or dashboards with Plotly.js? Chart Studio enables 1-click export, editing and sharing of Plotly.js charts. If building a full-stack app with Plotly.js, you might save time by building with Dash instead. Schedule a Dash Enterprise demo.


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.

These polar charts are legacy and will likely be deprecated in Plotly 2.0. Please see the new scatterpolar and scatterpolargl trace types for latest and greatest in Plotly polar coordinates.

Plotly.d3.csv('https://raw.githubusercontent.com/plotly/datasets/master/polar_dataset.csv', function(err, rows){
      function unpack(rows, key) {
          return rows.map(function(row)
          { return row[key]; });
      }
var trace1 = {
  r: unpack(rows, 'x1'),
  t: unpack(rows, 'y'),
  mode: 'lines',
  name: 'Figure8',
  marker: {
    color: 'none',
    line: {color: 'peru'}
  },
  type: 'scatter'
};

var trace2 = {
  r: unpack(rows, 'x2'),
  t: unpack(rows, 'y'),
  mode: 'lines',
  name: 'Cardioid',
  marker: {
    color: 'none',
    line: {color: 'darkviolet'}
  },
  type: 'scatter'
};

var trace3 = {
  r: unpack(rows, 'x3'),
  t: unpack(rows, 'y'),
  mode: 'lines',
  name: 'Hypercardioid',
  marker: {
    color: 'none',
    line: {color: 'deepskyblue'}
  },
  type: 'scatter'
};

var trace4 = {

  r: unpack(rows, 'x4'),
  t: unpack(rows, 'y'),
  mode: 'lines',
  name: 'Subcardioid',
  marker: {
    color: 'none',
    line: {color: 'orangered'}
  },
  type: 'scatter'
};

var trace5 = {

  r: unpack(rows, 'x5'),
  t: unpack(rows, 'y'),
  mode: 'lines',
  name: 'Supercardioid',
  marker: {
    color: 'none',
    line: {color: 'green'}
  },
  type: 'scatter'
};

var data = [trace1, trace2, trace3, trace4, trace5];

var layout = {
  title: 'Mic Patterns',
  font: {
    family: 'Arial, sans-serif;',
    size: 12,
    color: '#000'
  },
  showlegend: true,
  width: 480,
  height: 400,
  margin: {
    l: 40,
    r: 40,
    b: 20,
    t: 40,
    pad: 0
  },
  paper_bgcolor: 'rgb(255, 255, 255)',
  plot_bgcolor: 'rgb(255, 255, 255)',
  orientation: -90
};
Plotly.newPlot('myDiv', data, layout);
});
  function getrandom(num , mul)
  {
    var value = [ ]
    for(i=0;i<=num;i++)
     {
     rand = Math.random() * mul;
     value.push(rand);
     }
    return value;
  }
var trace1 = {
  r: getrandom(62, 3),
  t: getrandom(62, 300),
  mode: 'markers',
  name: 'Trial 1',
  marker: {
    color: 'rgb(27,158,119)',
    size: 110,
    line: {color: 'white'},
    opacity: 0.7
  },
  type: 'scatter'
};

var trace2 = {
  r: getrandom(72, 3),
  t: getrandom(72, 105),
  mode: 'markers',
  name: 'Trial 2',
  marker: {
    color: 'rgb(217,95,2)',
    size: 110,
    line: {color: 'white'},
    opacity: 0.7
  },
  type: 'scatter'
};

var trace3 = {
  r: getrandom(62, 3),
  t: getrandom(62, -100),
  mode: 'markers',
  name: 'Trial 3',
  marker: {
    color: 'rgb(117,112,179)',
    size: 110,
    line: {color: 'white'},
    opacity: 0.7
  },
  type: 'scatter'
};

var trace4 = {
  r: getrandom(62, 3),
  t: getrandom(62, -200),
  mode: 'markers',
  name: 'Trial 4',
  marker: {
    color: 'rgb(231,41,138)',
    size: 110,
    line: {color: 'white'},
    opacity: 0.7
  },
  type: 'scatter'
};

var trace5 = {

  r: getrandom(62, 3),
  t: getrandom(62, 250),
  mode: 'markers',
  name: 'Trial 5',
  marker: {
    color: 'rgb(102,166,30)',
    size: 110,
    line: {color: 'white'},
    opacity: 0.7
  },
  type: 'scatter'
};

var data = [trace1, trace2, trace3, trace4, trace5];

var layout = {
  title: 'Hobbs-Pearson Trials',
  font: {size: 15},
  plot_bgcolor: 'rgb(223, 223, 223)',
  angularaxis: {tickcolor: 'rgb(253,253,253)'}
};

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