1

您好,我需要您对 Google 饼图的帮助。我已经关注了这个谷歌图表链接,但它不起作用。如果您测试此代码,您可以看到图例和饼图相距甚远。我希望他们彼此靠近。我怎样才能做到这一点?

还有一件事:它的高度似乎是固定的,所以如果我在这个图表中添加更多行,它就会被隐藏......为什么?

<html><head>
<script type="text/javascript" src="https://www.google.com/jsapi"></script><script type="text/javascript">
google.load("visualization", "1.0", {"packages":["corechart"]});

google.setOnLoadCallback(drawChart0);
function drawChart0() {
var data = new google.visualization.DataTable();
data.addColumn("string", "ITEM");
data.addColumn("number", "VALUE"); 
data.addRows([`
    <!-- If I add more rows here some of them gets hidden...why? -->
["'Test1'", 4.5],
["'Test2'", 21.2],
["'Test3'", 31.4],
["'Test4'", 0.0],
["'Test5'", 31.4],
["'Test6'", 0.0],
["'Test7'", 11.5]]);

var options = {
"title":"My Piechart test",
titleTextStyle: {color: 'black', fontName: 'Arial', fontSize: '12', fontWidth: 'normal',bold: true},
sliceVisibilityThreshold:0,
is3D: true,
<!-- I want to have both legend and piechart beside each other -->
legend: {position: 'left',width:"100%",height:"100%"},
<!-- If I dont use "top", I can not see the title -->
chartArea:{left:2,top:20,position: 'left',width:"100%",height:"200%"}
};

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

</script></head><body>
<div id="chart_div0"></div>
</body></html>

我将此代码发送到 webView.loadDataWithBaseURL(null, contentHTML, "text/html", "utf-8", null); 我不认为 webview 是错误的,因为如果您尝试此 html 代码,您实际上可以看到问题也存在。所以我专注于它自己的html代码。

提前感谢您的所有帮助:)

4

0 回答 0