2016-10-21 05:12:10 +02:00
|
|
|
<!doctype html>
|
|
|
|
<html>
|
|
|
|
|
|
|
|
<head>
|
|
|
|
<title>Scatter Chart Multi Axis</title>
|
2020-05-25 22:54:22 +02:00
|
|
|
<script src="../../../dist/chart.min.js"></script>
|
2017-03-21 01:40:44 +01:00
|
|
|
<script src="../../utils.js"></script>
|
2016-10-21 05:12:10 +02:00
|
|
|
<style>
|
|
|
|
canvas {
|
|
|
|
-moz-user-select: none;
|
|
|
|
-webkit-user-select: none;
|
|
|
|
-ms-user-select: none;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
|
|
|
|
<body>
|
|
|
|
<div style="width:75%">
|
|
|
|
<canvas id="canvas"></canvas>
|
|
|
|
</div>
|
|
|
|
<button id="randomizeData">Randomize Data</button>
|
|
|
|
<script>
|
|
|
|
var color = Chart.helpers.color;
|
|
|
|
var scatterChartData = {
|
|
|
|
datasets: [{
|
2018-02-03 13:28:54 +01:00
|
|
|
label: 'My First dataset',
|
2019-11-22 00:46:49 +01:00
|
|
|
xAxisID: 'x',
|
|
|
|
yAxisID: 'y',
|
2016-10-21 05:12:10 +02:00
|
|
|
borderColor: window.chartColors.red,
|
|
|
|
backgroundColor: color(window.chartColors.red).alpha(0.2).rgbString(),
|
|
|
|
data: [{
|
|
|
|
x: randomScalingFactor(),
|
|
|
|
y: randomScalingFactor(),
|
|
|
|
}, {
|
|
|
|
x: randomScalingFactor(),
|
|
|
|
y: randomScalingFactor(),
|
|
|
|
}, {
|
|
|
|
x: randomScalingFactor(),
|
|
|
|
y: randomScalingFactor(),
|
|
|
|
}, {
|
|
|
|
x: randomScalingFactor(),
|
|
|
|
y: randomScalingFactor(),
|
|
|
|
}, {
|
|
|
|
x: randomScalingFactor(),
|
|
|
|
y: randomScalingFactor(),
|
|
|
|
}, {
|
|
|
|
x: randomScalingFactor(),
|
|
|
|
y: randomScalingFactor(),
|
|
|
|
}, {
|
|
|
|
x: randomScalingFactor(),
|
|
|
|
y: randomScalingFactor(),
|
|
|
|
}]
|
|
|
|
}, {
|
2018-02-03 13:28:54 +01:00
|
|
|
label: 'My Second dataset',
|
2019-11-22 00:46:49 +01:00
|
|
|
xAxisID: 'x',
|
|
|
|
yAxisID: 'y2',
|
2016-10-21 05:12:10 +02:00
|
|
|
borderColor: window.chartColors.blue,
|
|
|
|
backgroundColor: color(window.chartColors.blue).alpha(0.2).rgbString(),
|
|
|
|
data: [{
|
|
|
|
x: randomScalingFactor(),
|
|
|
|
y: randomScalingFactor(),
|
|
|
|
}, {
|
|
|
|
x: randomScalingFactor(),
|
|
|
|
y: randomScalingFactor(),
|
|
|
|
}, {
|
|
|
|
x: randomScalingFactor(),
|
|
|
|
y: randomScalingFactor(),
|
|
|
|
}, {
|
|
|
|
x: randomScalingFactor(),
|
|
|
|
y: randomScalingFactor(),
|
|
|
|
}, {
|
|
|
|
x: randomScalingFactor(),
|
|
|
|
y: randomScalingFactor(),
|
|
|
|
}, {
|
|
|
|
x: randomScalingFactor(),
|
|
|
|
y: randomScalingFactor(),
|
|
|
|
}, {
|
|
|
|
x: randomScalingFactor(),
|
|
|
|
y: randomScalingFactor(),
|
|
|
|
}]
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
|
|
|
|
window.onload = function() {
|
2018-02-03 13:28:54 +01:00
|
|
|
var ctx = document.getElementById('canvas').getContext('2d');
|
2019-10-30 23:41:41 +01:00
|
|
|
window.myScatter = new Chart(ctx, {
|
|
|
|
type: 'scatter',
|
2016-10-21 05:12:10 +02:00
|
|
|
data: scatterChartData,
|
|
|
|
options: {
|
|
|
|
responsive: true,
|
2020-10-19 13:24:06 +02:00
|
|
|
interaction: {
|
|
|
|
intersect: true,
|
|
|
|
mode: 'nearest'
|
|
|
|
},
|
2020-11-30 15:59:20 +01:00
|
|
|
plugins: {
|
|
|
|
title: {
|
|
|
|
display: true,
|
|
|
|
text: 'Chart.js Scatter Chart - Multi Axis'
|
|
|
|
}
|
2016-10-21 05:12:10 +02:00
|
|
|
},
|
|
|
|
scales: {
|
2019-11-22 00:46:49 +01:00
|
|
|
x: {
|
2018-02-03 13:28:54 +01:00
|
|
|
position: 'bottom',
|
2019-11-22 00:46:49 +01:00
|
|
|
},
|
|
|
|
y: {
|
2018-02-03 13:28:54 +01:00
|
|
|
type: 'linear', // only linear but allow scale type registration. This allows extensions to exist solely for log scale for instance
|
2016-10-21 05:12:10 +02:00
|
|
|
display: true,
|
2020-08-31 13:57:06 +02:00
|
|
|
position: 'left',
|
|
|
|
|
|
|
|
ticks: {
|
|
|
|
font: {
|
|
|
|
color: window.chartColors.red
|
|
|
|
}
|
|
|
|
}
|
2019-11-22 00:46:49 +01:00
|
|
|
},
|
|
|
|
y2: {
|
2018-02-03 13:28:54 +01:00
|
|
|
type: 'linear', // only linear but allow scale type registration. This allows extensions to exist solely for log scale for instance
|
2016-10-21 05:12:10 +02:00
|
|
|
display: true,
|
2018-02-03 13:28:54 +01:00
|
|
|
position: 'right',
|
2016-10-21 05:12:10 +02:00
|
|
|
reverse: true,
|
2017-03-21 01:40:44 +01:00
|
|
|
|
2020-08-31 13:57:06 +02:00
|
|
|
ticks: {
|
|
|
|
font: {
|
|
|
|
color: window.chartColors.blue
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-10-21 05:12:10 +02:00
|
|
|
gridLines: {
|
|
|
|
drawOnChartArea: false, // only want the grid lines for one axis to show up
|
2019-11-22 00:46:49 +01:00
|
|
|
}
|
|
|
|
}
|
2016-10-21 05:12:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
document.getElementById('randomizeData').addEventListener('click', function() {
|
|
|
|
scatterChartData.datasets.forEach(function(dataset) {
|
|
|
|
dataset.data = dataset.data.map(function() {
|
|
|
|
return {
|
|
|
|
x: randomScalingFactor(),
|
|
|
|
y: randomScalingFactor()
|
|
|
|
};
|
|
|
|
});
|
|
|
|
});
|
|
|
|
window.myScatter.update();
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
|
|
|
|
</html>
|