JavaScript
var data1 = [0.001, 0.002, 0.005, 0.005, 0.006, 0.006, 0.012, 0.012, 0.013, 0.013, 0.013, 0.015];
var data2 = [0, 0.002, 0.002, 0.003, 0.003, 0.003, 0.003, 0.003, 0.005, 0.005, 0.009, 0.009];
var maxticks = 12;
var max1 = _.max(data1)
var max2 = _.max(data2)
var maxSize = max1 > max2 ? max1 : max2;
var stepSize = maxSize / maxticks;
function calcMaxSize(max, step, dec) {
let out = 0
out = _.ceil(max / step)
out = out * step + step
out = _.ceil(out, dec)
return out
}
switch (true) {
case stepSize > 1:
stepSize = 2
maxSize = calcMaxSize(maxSize, stepSize, 0)
break
case stepSize > 0.1:
stepSize = 0.4
maxSize = calcMaxSize(maxSize, stepSize, 1)
break
case stepSize > 0.01:
stepSize = 0.04
maxSize = calcMaxSize(maxSize, stepSize, 2)
break
case stepSize > 0.001:
stepSize = 0.004
maxSize = calcMaxSize(maxSize, stepSize, 3)
break
}
console.log(data1);
console.log(data2);
console.log(maxSize);
console.log(stepSize);
var ctx = document.getElementById('myChart').getContext('2d');
var chart = new Chart(ctx, {
data: {
labels: ["J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"],
datasets: [{
label: 'KU1',
yAxisID: 'axis-accumulation',
data: data1,
type: 'line',
backgroundColor: 'transparent',
borderColor: 'rgba(232, 62, 140, 0.5)',
pointBackgroundColor: 'rgba(232, 62, 140, 0.5)',
pointBorderWidth: 0,
pointRadius: 2,
borderWidth: 1,
datalabels: {
display: false,
},
}, {
label: 'KU2',
yAxisID: 'axis-accumulation',
data: data2,
type: 'line',
backgroundColor: 'transparent',
borderColor: 'rgba(120, 21, 185, 0.5)',
pointBackgroundColor: 'rgba(120, 21, 185, 0.5)',
pointBorderWidth: 0,
pointRadius: 2,
borderWidth: 1,
datalabels: {
display: false,
},
}],
},
// Configuration options go here
options: {
responsive: true,
...