jcode/skills/data-visualization/template.html

31 lines
1.1 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Chart</title>
<script src="https://cdn.plot.ly/plotly-2.35.2.min.js"></script>
<style>
body { margin: 0; font-family: system-ui, sans-serif; background: #fff; }
#chart { width: 100%; max-width: 1000px; height: 560px; margin: 24px auto; }
#error { color: #b00020; text-align: center; }
</style>
</head>
<body>
<div id="chart"></div>
<p id="error"></p>
<!-- The chart: replace the JSON below. "traces" = list of Plotly traces, "layout" = Plotly layout. -->
<script id="chart-data" type="application/json">{"traces": [], "layout": {}}</script>
<script>
try {
const spec = JSON.parse(document.getElementById("chart-data").textContent);
const layout = Object.assign({margin: {t: 60, r: 30}, colorway:
["#4477AA", "#EE6677", "#228833", "#CCBB44", "#66CCEE", "#AA3377"]}, spec.layout); // colour-blind safe
Plotly.newPlot("chart", spec.traces, layout, {responsive: true, displaylogo: false});
} catch (e) {
document.getElementById("error").textContent = "Chart could not be drawn: " + e.message;
}
</script>
</body>
</html>