I'm trying to plot a chart as shown in the screen capture and I would like to shift the y-axis to the center of the x axis using existing charting fw like chart.js. Done a search but can't really find any answers.
Chart
Asked
Active
Viewed 450 times
0

DanialChan
- 100
- 7
-
Please post the code on what you have tried. – Sasi Kumar M Jul 01 '19 at 13:01
-
I used a demo line chart. Possible values for position of axis are : 'top', 'left', 'bottom', 'right'. There is no config to set it to the center so I'm asking if anyone has experience to centre it – DanialChan Jul 01 '19 at 13:08
1 Answers
0
You can use the position
option in the scale config and set it to 'center'
like so:
const options = {
type: 'line',
data: {
labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
datasets: [{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
borderColor: 'pink'
},
{
label: '# of Points',
data: [7, 11, 5, 8, 3, 7],
borderColor: 'orange'
}
]
},
options: {
scales: {
y: {
position: 'center'
}
}
}
}
const ctx = document.getElementById('chartJSContainer').getContext('2d');
new Chart(ctx, options);
<body>
<canvas id="chartJSContainer" width="600" height="400"></canvas>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.6.0/chart.js"></script>
</body>

LeeLenalee
- 27,463
- 6
- 45
- 69