Skip to content

Instantly share code, notes, and snippets.

@gh640
Created December 1, 2018 14:16
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 gh640/1571c937d3cfb0fd0a3a430964f80346 to your computer and use it in GitHub Desktop.
Save gh640/1571c937d3cfb0fd0a3a430964f80346 to your computer and use it in GitHub Desktop.
Chart.js sample: Scatter chart with straight lines
<!DOCTYPE>
<html>
<body>
<canvas id="canvas"></canvas>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.3/Chart.min.js"></script>
<script>
// see: https://www.chartjs.org/docs/latest/charts/scatter.html
// see: https://stackoverflow.com/questions/46232699/display-line-chart-with-connected-dots-using-chartjs
const ctx = document.querySelector('#canvas');
const scatterChart = new Chart(ctx, {
type: 'scatter',
data: {
datasets: [{
label: 'Scatter Dataset',
data: [
{
x: -10,
y: 0
}, {
x: 0,
y: 10
}, {
x: 10,
y: 5
}, {
x: 8,
y: 4
}, {
x: -4,
y: 2
},
],
borderWidth: 5,
showLine: true,
fill: false,
lineTension: false,
}]
},
options: {
scales: {
xAxes: [{
type: 'linear',
position: 'bottom',
}],
},
},
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment