簡體   English   中英

Chart.JS如何更改y軸的順序

[英]Chart.JS how to change order of y-axis

我圖的y軸從1到20(最小到最大),但我希望y軸從20到1(最大到最小)。最大數從圖形的底部開始,並隨着您的上升圖表直到達到最小值。我似乎找不到執行此操作的語法。 我正在使用chart.js來做到這一點

<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>

反向使用:對於yAxes配置為true

yAxes: [
        {
            reverse: true, // will reverse the scale
        }
    ]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM