admin管理员组文章数量:1394520
The y-axis on my graph goes from 1 to 20 (min to max), but I want the y-axis to go from 20 to 1 (max to min) The max number starting at the base of the graph and decreases as you go up the graph until you reach the min.I can't seem to find the syntax to perform this. I am using chart.js to do this
<script>
var myChart = document.getElementById("myChart").getContext("2d");
var historyChart = new Chart(myChart, {
type:'line',
data:{
labels:['2012/13', '2013/14', '2014/15', '2015/16', '2016/17'],
datasets:[{
label: 'League Position',
fill: false,
lineTension: 0.1,
backgroundColor: "blue",
borderColor: "black",
borderCapStyle: 'butt',
data: [15, 11, 17, 13, 4]
}]
},
options:{
title: {
display: true,
text: 'League History'
},
scales: {
yAxes : [{
ticks : {
fontSize: 14,
max : 20,
min : 1,
stepSize: 1,
}
}],
xAxes : [{
ticks : {
fontSize: 14,
}
}]
}
}
});
</script>
The y-axis on my graph goes from 1 to 20 (min to max), but I want the y-axis to go from 20 to 1 (max to min) The max number starting at the base of the graph and decreases as you go up the graph until you reach the min.I can't seem to find the syntax to perform this. I am using chart.js to do this
<script>
var myChart = document.getElementById("myChart").getContext("2d");
var historyChart = new Chart(myChart, {
type:'line',
data:{
labels:['2012/13', '2013/14', '2014/15', '2015/16', '2016/17'],
datasets:[{
label: 'League Position',
fill: false,
lineTension: 0.1,
backgroundColor: "blue",
borderColor: "black",
borderCapStyle: 'butt',
data: [15, 11, 17, 13, 4]
}]
},
options:{
title: {
display: true,
text: 'League History'
},
scales: {
yAxes : [{
ticks : {
fontSize: 14,
max : 20,
min : 1,
stepSize: 1,
}
}],
xAxes : [{
ticks : {
fontSize: 14,
}
}]
}
}
});
</script>
Share
Improve this question
edited Nov 12, 2017 at 23:49
Workkkkk
asked Nov 12, 2017 at 23:29
WorkkkkkWorkkkkk
2851 gold badge7 silver badges24 bronze badges
2
- Don't forget to up vote! – Chandan Rauniyar Commented Nov 13, 2017 at 12:01
- Yes sir!!!!!!!! :) – Workkkkk Commented Nov 13, 2017 at 17:55
1 Answer
Reset to default 8Use reverse: true for yAxes configuration
yAxes: [
{
reverse: true, // will reverse the scale
}
]
本文标签: javascriptChartJS how to change order of yaxisStack Overflow
版权声明:本文标题:javascript - Chart.JS how to change order of y-axis - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744101535a2590892.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论