我想更改chartjs中标签的值

时间:2019-05-21 08:44:38

标签: chart.js

我想在chartjs中更改饼图中的标签值,我想显示悬停饼图时处于暂停状态的座席总数,处于呼叫状态的座席总数以及就绪状态。当我在标签中放置一个值时,它也会显示在悬停标签上。我就像被这东西卡住了。预先感谢

   $(document).ready(function(){
   $.ajax({
  url: "http://localhost/ci/login/agend_data",
method: "GET",
success: function(data1) {
  var data = JSON.parse(data1);

  var paused = [];
  var incall = [];
  var ready = [];
  var pause_agent = [];
  var incall_agent = [];
  var ready_agent = [];
  for (var i in data) {
    if(data[i].status=='PAUSED') {
        pause_agent.push(data[i].conf_exten);
        paused.push('paused');
    } else if (data[i].status=='INCALL') {
        incall_agent.push(data[i].conf_exten);
        incall.push('incall');
    } else {
        ready_agent.push(data[i].conf_exten);
        ready.push('ready');
    }
  }
  var Paused = paused.length;
  var Incall = incall.length;
  var Ready = ready.length;

  var chartdata = {
    labels: ['paused', 'incall', 'ready'],
    datasets : [
      {
        label: 'Agent',
        backgroundColor: ['red', 'blue', 'green'],
        borderColor: 'rgba(200, 200, 200, 0.75)',
        hoverBackgroundColor: '#bbb',
        hoverBorderColor: 'rgba(200, 200, 200, 1)',
        data: [Paused, Incall, Ready]

      }
    ],

  };

  var ctx = $("#mycanvas");

  var barGraph = new Chart(ctx, {
    type: 'pie',
    data: chartdata,
   options: {
          tooltips: {
            callbacks: {
              label: function(tooltipItem) {


              }
            }
          }
        }
  });
},
error: function(data) {
  console.log(data);
}
});
});

0 个答案:

没有答案