如何向Google图表添加数据标签 [英] How to add data labels to a Google Chart

查看:175
本文介绍了如何向Google图表添加数据标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Google Chart API创建了一个饼图,但是无法控制要添加哪些数据标签。我希望能够为每块馅饼添加一个标签。谁能提供有关如何执行此操作的任何见解?

I've created a pie chart using the Google Chart API but am unable to control which data labels are added. I'd like to be able to add a label for each slice of the pie. Can anyone provide any insight on how to go about doing this?

下图的代码:

   <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
      google.load("visualization", "1", {packages:["corechart"]});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = google.visualization.arrayToDataTable([
          ['Resource', 'Percentage'],
          ['Video',     517],
          ['Download',      13],
          ['Tool',      13],
          ['Video and Download',  15],
          ['Video and Tool', 59],
          ['Download Video and Tool',    5]
        ]);

        var options = {
          title: '',
      is3D: 'true',
      colors: ['592C81', '799A3D', '863375', '5B5B5B', '004A97', 'B8BABD' ]
        };

        var chart = new google.visualization.PieChart(document.getElementById('piechart_3d'));
        chart.draw(data, options);
      }
    </script>
  </head>
  <body>
    <div id="piechart_3d" style="width: 900px; height: 500px;"></div>


推荐答案

由于每个切片中的空间不足,因此看起来最好的办法就是添加

Since there's not enough room in each slice, looks like the best you can do is add

 legend: { position: 'labeled' }

您的选项。

示例此处

这篇关于如何向Google图表添加数据标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆