Skip to content

Instantly share code, notes, and snippets.

@infantiablue
Last active April 28, 2021 08:37
Show Gist options
  • Save infantiablue/8cd26ad56806498645521f6bacd61e37 to your computer and use it in GitHub Desktop.
Save infantiablue/8cd26ad56806498645521f6bacd61e37 to your computer and use it in GitHub Desktop.
const initChart = (data) => {
let trace_price = {
name: "Price ($)",
x: data.index.map((t) => new Date(t)),
y: data.price,
xaxis: "x",
yaxis: "y1",
type: "scatter",
mode: "lines+markers",
marker: { color: "blue", size: 3 },
};
let trace_volumes = {
name: "Volumne ($B)",
x: data.index.map((t) => new Date(t)),
y: data.volumes,
xaxis: "x",
yaxis: "y2",
type: "bar",
barmode: "relative",
marker: {
color: "rgb(49,130,189)",
opacity: 0.7,
},
};
let layout = {
autosize: true,
height: "100%",
margin: {
l: 50,
r: 20,
t: 35,
pad: 3,
},
showlegend: false,
xaxis: {
domain: [1, 1],
anchor: "y2",
},
yaxis: {
domain: [0.1, 1],
anchor: "x",
},
yaxis2: {
showticklabels: false,
domain: [0, 0.1],
anchor: "x",
},
grid: {
roworder: "bottom to top",
},
};
let config = { responsive: true };
let series = [trace_price, trace_volumes];
Plotly.newPlot("chart", series, layout, config);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment