how to change the text 'no data' in google pie chart

送分小仙女□ 提交于 2020-01-25 02:54:09

问题


if i am passing empty data for chart binding it shows 'no data' i need to change the text 'no data' to some other word.

  google.load("visualization", "1", {packages:["corechart"]});
  google.setOnLoadCallback(drawChart);
  function drawChart() {
    var data = google.visualization.arrayToDataTable([
      ['Task', 'Hours per Day']

    ]);

    var options = {
      title: 'My Daily Activities'
    };

    var chart = new google.visualization.PieChart(document.getElementById('piechart'));
    chart.draw(data, options);
  }


回答1:


You can do it manually:

if(data.getNumberOfRows() == 0){
    $("#piechart").append("Sorry, not info available")
}else{
    var chart = new google.visualization.PieChart(document.getElementById('piechart'));
    chart.draw(data, options);        
}



回答2:


As juvian said data.getNuberOfRows() is in the plugin, so if you are good with jquery you can even replace " $("#piechart").append("Sorry, not info available")" with an image for example

if (data.getNumberOfRows() == 0) {

   $("#someimage").attr("src","url-to-image");//Or any jquery dom manipulation here

} else {

var chart = new 
google.visualization.PieChart(document.getElementById('piechart'));
chart.draw(data, options);        
}


来源:https://stackoverflow.com/questions/27380516/how-to-change-the-text-no-data-in-google-pie-chart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!