问题
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?
Code for the chart below:
<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>
回答1:
Since there's not enough room in each slice, looks like the best you can do is add
legend: { position: 'labeled' }
to your options.
Example here.
来源:https://stackoverflow.com/questions/26814107/how-to-add-data-labels-to-a-google-chart