Skip to content

Instantly share code, notes, and snippets.

@jwilber
Created September 9, 2019 03:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jwilber/e501f4d98833907ab5a2a4d20405fc48 to your computer and use it in GitHub Desktop.
Save jwilber/e501f4d98833907ab5a2a4d20405fc48 to your computer and use it in GitHub Desktop.
xkcd line chart
license: mit
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.xkcd@1/dist/chart.xkcd.min.js"></script>
<style>
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
</style>
</head>
<body>
<svg class="line-chart"></svg>
<script>
const svg = document.querySelector('.line-chart')
const lineChart = new chartXkcd.Line(svg, {
title: 'Monthly income of an indie developer', // optional
xLabel: 'Month', // optional
yLabel: '$ Dollors', // optional
data: {
labels: ['1', 'two', '3', '4'],
datasets: [{
label: 'Plan',
data: [30, 70, 200, 100, 100, 100, 1500, 2900, 5000, 800],
}, {
label: 'Reality',
data: [0, 9000, 30, 70, 80, 100, 50, 80, 40, 150],
}],
},
options: { // optional
yTickCount: 3,
legendPosition: chartXkcd.config.positionType.upLeft
}
});
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment