Created
December 1, 2018 14:16
-
-
Save gh640/1571c937d3cfb0fd0a3a430964f80346 to your computer and use it in GitHub Desktop.
Chart.js sample: Scatter chart with straight lines
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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