Chart.js issue
by Marvin Heilemann
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.min.js"></script>
<canvas id="myChart"></canvas>
JavaScript
var data = [0.99, 1.786, 2.839, 3.715, 4.603, 5.318, 6.188, 7.722, 9.121, 10.589, 11.713, 13.21];
var maxSize = Math.ceil(Math.max(...data)); // max of data
var stepSize = Math.round(maxSize / data.length);
console.log(data);
console.log(maxSize);
console.log(stepSize);
var ctx = document.getElementById('myChart').getContext('2d');
var chart = new Chart(ctx, {
data: {
label: 'KU',
yAxisID: 'axis-accumulation',
data: data,
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,
},
},
// Configuration options go here
options: {
responsive: true,
title: {
display: true,
text: "KS"
},
verticalGuide: {
color: '#2d2d2d',
},
hover: {
mode: 'index',
intersect: false,
},
tooltips: {
mode: 'index',
intersect: false,
position: 'nearest',
bodySpacing: 6,
callbacks: {
label: tooltipItem => {
let val = tooltipItem.yLabel
if (val == 0) {
val = val + '≤'
}
return val + ' Mio €'
},
},
},
scales: {
yAxes: [{
id: 'axis-accumulation',
gridLines: {
display: true,
color: '#f3d3e4',
},
ticks: {
beginAtZero: true,
maxTicksLimit: data.length + 1, // +1 for zero
stepSize: stepSize,
max: maxSize,
min: 0,
autoSkip: false,
},
position: 'right',
}, ],
},
}
});