Published
Edited
Apr 21, 2021
1 fork
Insert cell
Insert cell
{
const x = [1, 2, 3, 4, 5],
y = [10, 20, 30, 20, 10];
const data = [
{
x: x,
y: y,
type: 'scatter',
mode: 'markers',
marker: { size: 20, color: "red" }
}
];
const layout = { hovermode: 'closest', title: 'Click on Points' };
const myDiv = DOM.element('mydiv'); //html`<div id="myDiv" style="width: 700px; height: 500px;"></div>`;
Plotly.newPlot(myDiv, data, layout);
let count = 0;
myDiv.on('plotly_click', data => {
mutable feedback = data;
const update = {
marker: { color: d3.schemeCategory10[count % 10], size: 20 }
};
Plotly.restyle(myDiv, update, [0]);
count++;
});
return myDiv;
}
Insert cell
mutable feedback = ""
Insert cell
d3.schemeCategory10.slice()
Insert cell
Insert cell
feedback
Insert cell
md`### External Libraries and Imports`
Insert cell
Plotly = require("plotly.js-dist")
Insert cell
d3 = require("d3@6")
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more