Radial Lines with Tips
Four stocks' closing prices as lines in polar coordinates, with a shared tip: cm.nearestX with shared: "x" selects every stock at the date nearest the pointer by angle, a dot marks each on its line, and one tip lists them, beside a spoke at the date. Hover to see the prices.
js
// The stocks of Plot's labeled multi-line chart: four CSV files merged into one table, with the
// symbol of each stock as its first column.
const symbols = ["AAPL", "AMZN", "GOOG", "IBM"];
const tables = await Promise.all(symbols.map((symbol) => d3.csv(`/data/${symbol.toLowerCase()}.csv`, d3.autoType)));
const data = symbols.flatMap((Symbol, i) => tables[i].map((d) => ({Symbol, ...d})));
const hover = cm.selection();
const renderer = cm.svg({width: 640, height: 640});
const root = cm.flow().renderer(renderer);
root
.data(data)
.transform(cm.encode, {x: "Date", y: "Close", stroke: "Symbol"})
.transform(cm.polar, {
innerRadius: 0.2,
x: {axis: "outer"},
y: {type: "linear", axis: true},
stroke: {legend: true},
})
.add(cm.lineRadial)
.add(cm.circle, {filter: hover, r: 3.5, fill: "stroke", stroke: "white", strokeWidth: 1})
.add(cm.nearestX, {as: hover, shared: "x"})
.add(cm.tip, {filter: hover, shared: true, rule: true, format: {Close: (d) => d.toFixed(2)}});
root.render();
document.body.append(renderer.node());