Skip to content

Instantly share code, notes, and snippets.

@exactlyallan
Last active December 6, 2022 23:27
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 exactlyallan/e4b7cff5e519110223cffa123ddc4fec to your computer and use it in GitHub Desktop.
Save exactlyallan/e4b7cff5e519110223cffa123ddc4fec to your computer and use it in GitHub Desktop.
Simple Chart.js Scatter
<html>
<head>
<meta charset="utf-8">
<title>Simple Scatter</title>
</head>
<body>
<h2>Scatter Example</h2>
<canvas id="scatter" width="600" height="400"></canvas>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/4.0.1/chart.umd.min.js" integrity="sha512-HyprZz2W40JOnIBIXDYHCFlkSscDdYaNe2FYl34g1DOmE9J+zEPoT4HHHZ2b3+milFBtiKVWb4sorDVVp+iuqA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script>
const data = {
datasets: [{
label: 'Scatter Dataset',
data: [{
x: -10,
y: 0
}, {
x: 0,
y: 10
}, {
x: 10,
y: 5
}, {
x: 0.5,
y: 5.5
}],
backgroundColor: 'rgb(255, 99, 132)'
}],
};
const config = {
type: 'scatter',
data: data,
options: {
scales: {
x: {
type: 'linear',
position: 'bottom'
}
}
}
};
const ctx = document.getElementById('scatter');
new Chart(ctx, config)
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment