Skip to content

Radar ​

What people value in a phone, with an axis for each attribute. cm.fold folds the phones into a row per attribute, and with {y: {by: "x"}}, cm.polar gives each spoke its own radius, from 0 to a round maximum of its attribute, with its own axis of three ticks and three evenly spaced rings. The "catmull-rom-closed" curve keeps the shapes within the disc. After Observable Plot.

js
const attributes = [
  "Battery Life",
  "Brand",
  "Contract Cost",
  "Design And Quality",
  "Have Internet Connectivity",
  "Large Screen",
  "Price Of Device",
  "To Be A Smartphone",
];

const phones = [
  {name: "iPhone", values: [0.22, 0.28, 0.29, 0.17, 0.22, 0.02, 0.21, 0.5]},
  {name: "Samsung", values: [0.27, 0.16, 0.35, 0.13, 0.2, 0.13, 0.35, 0.38]},
  {name: "Nokia Smartphone", values: [0.26, 0.1, 0.3, 0.14, 0.22, 0.04, 0.41, 0.3]},
];

const data = phones.map(({name, values}) => ({
  name,
  ...Object.fromEntries(attributes.map((a, i) => [a, values[i]])),
}));

const renderer = cm.svg({width: 640, height: 560});
const root = cm.flow().renderer(renderer);

root
  .data(data)
  .transform(cm.encode, {stroke: "name", fill: "name"})
  .transform(cm.fold, {x: attributes})
  .transform(cm.polar, {
    x: {axis: "outer", grid: true},
    y: {by: "x", nice: true, axis: true, ticks: 3, rings: 3},
    stroke: {legend: true},
  })
  .add(cm.areaRadial, {y1: () => 0, fillOpacity: 0.1, stroke: null, curve: "catmull-rom-closed"})
  .add(cm.lineRadial, {curve: "catmull-rom-closed"})
  .add(cm.circle, {r: 3, stroke: null});

root.render();
document.body.append(renderer.node());