簡體   English   中英

Chart.js x 軸不工作?

[英]Chart.js x-axes not working?

我正在嘗試制作一個顯示數據的圖表。 我似乎無法讓 x 軸工作。 如果我添加 type:'linear',則它不會顯示數據,但會顯示 x 軸。 如果我不添加它,則會顯示數據,但 x 軸不起作用。

    var chart = new Chart(document.getElementById("graph"), 
    {
    type: 'line',
        data: {
        //labels: [1500,1600,1700,1750,1800,1850,1900,1950,1999,2050],
        datasets: [{ 
        display: true,
        data: [86,114,106,106,107,111,133,221,783,2478],
        label: "Africa",
        borderColor: "#3e95cd",
        fill: false
      }
    ]
    },
    options: {
        scaleShowValues: true,
        responsive: false,
        title: {
          display: true,
          text: 'World population (in millions)'
    },

    scales: {
        yAxes: [
            {
              type: 'linear',
              ticks: {
                beginAtZero:true,
                min: -10,
                max: 110,

              }
        }
      ],
      xAxes: [{
        display: true,
        position: 'bottom',
        //type: 'linear',

        ticks: {
          display:true,          
          min: 0,
          max: 3000,
          stepSize: 10,
          autoSkip: true



              }
            }
          ]
        }
    }
});

數據不適合圖表類型,應該有兩個坐標“ x”和“ y”。 折線圖必須具有以下數據:

data: [{
        x: 10,
        y: 20
    }, {
        x: 15,
        y: 10
    }]

並刪除這些行:最小值:-10,最大值:110,這樣圖形看起來更漂亮並且知道如何調整 Y 值本身。

暫無
暫無

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

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