Say I have a line chart: https://jsfiddle.net/13fyhL4j/
HTML:
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.1.3/Chart.js"></script>
<canvas id="myChart" width="400" height="400"></canvas>
JS:
var ctx = document.getElementById("myChart");
var yLabels = [0, 2, 3, 6, 7];
var xLabels = ['A', 'B', 'C', 'D', 'E'];
var myChart = new Chart(ctx, {
type: 'line',
data: {
labels: xLabels,
datasets: [
{
type: 'line',
label: 'Line',
data: yLabels,
fill: false,
}
]
},
options:{
scales: {
xAxes: [{
display: true,
scaleLabel: {
display: true,
labelString: 'x label'
},
}],
yAxes: [{
display: true,
scaleLabel: {
display: true,
labelString: 'y label'
},
}]
}
}
});
Here, the x axis has a category scale, and the y axis has a linear scale. I need to swap the axis, however I cannot find how to make the linear x axis and y axis.
Image explanation
It is necessary to change not only the axis values, but also the graph itself.
source
share