Chart.js带有客户X轴标签的气泡图

时间:2016-06-13 02:25:16

标签: javascript angularjs charts chart.js

无论如何,我可以将X轴标签自定义为单词而不是数字刻度吗? 我尝试在我的数据中插入labels属性,但它不起作用。

这是我的代码:

var bubbleChartData = 
    {

        datasets: [
        {
            label: "My First dataset",
            backgroundColor: randomColor(),
            data: [4, 2, 3, 4, 5]
        }],
        labels: [
            "Bad",
            "Average",
            "Good",
            "Very Good",
            "Perfect"
        ]   
    };

    window.onload = function() {
        var ctx = document.getElementById("canvas").getContext("2d");
        window.myChart = new Chart(ctx, {
            type: 'bubble',
            data: bubbleChartData,
            xAxisID: 'testing',
            options: {

                responsive: true,
                title:{
                    display: true,
                    text:'Chart.js Bubble Chart'
                },


            }
        });
    };

这是我得到的: enter image description here

1 个答案:

答案 0 :(得分:3)

将xAxes的回调用于您的选项:

options: {
  responsive: true,
  title:{
      display: true,
      text:'Chart.js Bubble Chart'
  },    
  scales: {
    xAxes: [{
      ticks: {
        callback: function(value, index, values) {
          return 'value is ' + value;
        }
      }
    }]
  }
}