I am using following code to plot a graph in which x-axis is logarithmic but labels on the x-axis are being displayed in scientific notation. I want them to appear like the numbers used in the data. I have tried using callback: function (value, index, values)
but plot disappear after using these. Can somebody help me that what should I change to get this right.
PS. I cannot use charts.js above version 2.9.4 due to some limitations.
Best Regards.
<!DOCTYPE html>
<!-- saved from url=(0014)about:internet -->
<html>
<head>
<title>Chart</title>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=Edge'>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-colorschemes"></script>
<style>
body { margin: 0; padding: 0; }
#container { width: 100%; }
</style>
</head>
<body>
<div id='container'>
<canvas id='myChart'></canvas>
</div>
<script>
Chart.defaults.global.animation.duration = 1000;
Chart.defaults.global.animation.easing = 'linear';
var ctx = document.getElementById('myChart').getContext('2d');
var myChart = new Chart(ctx, {
type: 'line',
data: {
labels: ['10','2000','30000','50000','60000','700000',],
datasets: [
{label: 'ABC' ,
fill: true ,
data: [
{ x: '10', y: 2 },
{ x: '2000', y: 4 },
{ x: '30000', y: 7 },
{ x: '50000', y: 8 },
{ x: '60000', y: 8.5 },
{ x: '700000', y: 9 }
],
borderWidth: 1},
]
},
options: {
aspectRatio: 1.6,
title: {
display: true,
position: 'top',
text: 'Ref Data'
},
legend: {
display: true,
position: 'right',
},
scales: {
yAxes: [{
id: 'first-y-Axis',
display: true,
scaleLabel: {
display: true,
labelString: 'Demo y-axis'
}
}],
xAxes: [{
id: 'first-x-Axis',
display: true,
type: 'logarithmic',
scaleLabel: {
display: true,
labelString: 'Demo x-axis'
},
ticks: {
min: 0 ,
max: 700000
//Following commented line were copied from internet for the solution but chart is shown blank after uncommenting these
//callback: function (value, index, values) {
//return Number(value.toString()) //pass tick values as a string into Number function
//}
}
}]
},
plugins: {
colorschemes: {
scheme: 'brewer.Paired12'
}
}
}
});
</script>
</body>
</html>