【发布时间】:2017-06-28 10:06:12
【问题描述】:
我是 angularjs 和谷歌图表的新手,我现在制作了一个饼图,我想要以下内容:
1- display total components inside the centre of the pie charts.
2- display pieSliceText outer side of the pie slice
如何做到这一点 我的示例代码:
<script type="text/javascript" src="https://www.google.com/jsapi?autoload={'modules':[{'name':'visualization','version':'1.1','packages':['corechart']}]}"> </script>
<div id="piechart" style="width: 900px; height: 500px;"></div>
javascript:
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Task', 'Hours per Day'],
['Work', 11],
['Eat', 2],
['Commute', 2],
['Watch TV', 2],
['Sleep', 7]
]);
var options = {
height: 360,
width: 360,
pieHole: 0.5,
showLables: 'true',
pieSliceText: 'value',
pieSliceTextStyle: {
color: 'white',
fontSize:18
},
legend: {
position: 'right',
alignment: 'center'
},
chartArea: {
left: 10,
top: 10,
width: '130%',
height: '65%'
},
tooltip: {
trigger:'none'
}
};
var chart = new google.visualization.PieChart(document.getElementById('piechart'));
chart.draw(data, options);
}
【问题讨论】:
-
-
好吧,我不这么认为。但还是。你读过这篇文章并尝试过它的任何部分吗? developers.google.com/chart/interactive/docs/overlays我拿了你的图表并用它来放置中间组件。标签可能需要在绘制图表后用 JS 移动它们。
-
@KevinBrown 我在 google 开发人员上阅读了有关 google 图表的文档,但找不到像快照一样显示甜甜圈内的一些组件的方法,请您为它创建一个 plunker 吗?
-
@in 我没有制作像这个新的 google.visualization.LineChart 这样的任何对象,我只是在变量中添加数据,并在我的 html 中放置 google-charts 指令组件