I’ve just started learning plot/d3, and am stuck at trying to reproduce the “stocks” examples as in the one at Plots | Observable Plot and at Normalize transform | Observable Plot.
I’ve downloaded a couple of stock data files in csv format Yahoo finance and have managed to load and plot them as follows:
async function drawGraph() {
const goog = await d3.csv('GOOG.csv');
const nflx = await d3.csv('NFLX.csv');
const plot = Plot.plot({
x: {
transform: (d) => new Date(d),
line: true,
},
y: {
transform: (d) => +d,
line: true,
label: "Normalised Adj Close"
},
color: {
legend: true
},
marginTop: 20,
marginRight: 20,
marginBottom: 30,
marginLeft: 40,
grid: true,
marks: [
Plot.line(goog, Plot.normalizeY({x: "Date", y: "Adj Close", stroke: "red"})),
Plot.line(nflx, Plot.normalizeY({x: "Date", y: "Adj Close", stroke: "blue"}))
]
});
const div = document.querySelector("#myplot");
div.append(plot);
}
drawGraph();
The snag I have is the color: { legend: true }
entry seems to be getting completely ignored for reasons I don’t understand.
If I try to add text labels along the lines of the example in normalize, ie
marks: [
Plot.line(goog, Plot.normalizeY({x: "Date", y: "Adj Close", stroke: "red"})),
Plot.line(nflx, Plot.normalizeY({x: "Date", y: "Adj Close", stroke: "blue"})),
Plot.text(goog, Plot.selectLast(Plot.normalizeY({x: "Date", y: "Adj Close", text: "GOOG", textAnchor: "start", dx: 3}))),
Plot.text(nflx, Plot.selectLast(Plot.normalizeY({x: "Date", y: "Adj Close", text: "NFLX", textAnchor: "start", dx: 3})))
]
also gets ignored.
I’m guessing the data used in the documentation examples has stuff my data doesn’t but I don’t know how to access that data to see what I’m doing wrong.