How do I format numbers in ChartJS for axis and tooltips? I looked everywhere, but I could not find any example.
Looking at the code on Github it seems possible, but can't understand how to do it.
I have a logarithmic scale from 1e-5. I have tried:
scales: {
x: {
ticks: {
beginAtZero: true,
display: true,
autoSkip: true,
maxTicksLimit: 11,
maxRotation: 0
}
},
Residuals: {
type: 'logarithmic',
title: {
display: true,
text: 'Residuals'
},
position: 'left',
ticks: {
beginAtZero: false,
display: true,
format: "scientific"
},
max: 1.0,
min: convergence / 10.0
}
}
but unfortunately it does not work.
EDIT
Just to add to the answer. For tooltips you can use a similar approach
plugins: {
tooltip: {
callbacks: {
label: function(context) {
var label = context.dataset.label
label += ": "
label += Number.parseFloat(context.parsed.y).toExponential(2); // limit to 2 decimal numbers
return label
}
}
}
}