简体   繁体   中英

Chart.js Bubble chart with custome X-axis labels

Is there anyway I can customize the X-axis label to words instead of numbers scale? I tried inserting the labels attribute in my data, but it doesn't work.

this is my code:

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'
                },


            }
        });
    };

this is what i got: 在此输入图像描述

Use a callback for xAxes into your options:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM