我正在使用Google Charts创建饼图。到目前为止一切正常。我想删除值并在将鼠标悬停在切片上时保持工具提示的百分比。
我尝试添加:
tooltip: {
text: 'percentage'
}
(我建议在这里搜索答案时这样做) 致我:
Var piechart_options = {
title:'Portföljfördelning',
is3D: true,
width:600,
height:400
};
如:
Var piechart_options = {
title:'Portföljfördelning',
is3D: true,
width:600,
height:400
tooltip: {
text: 'percentage'
}
};
不幸的是没有成功。当我添加它时,图表甚至不再被绘制。有什么建议吗?
完整代码:
<?php
$result = mysqli_fetch_assoc(db_query("SELECT * FROM investments ORDER BY id DESC LIMIT 1;"));
echo '<div style="display: none;">';
foreach($result as $key => $value) {
echo '<p class="investment_type">'. $key .'</p>';
echo '<p class="investment_amount">'. $value .'</p>';
}
echo '</div>'
?>
<script>
var type = document.getElementsByClassName("investment_type");
var amount = document.getElementsByClassName("investment_amount");
var investment_type = [];
var investment_amount = [];
for(var i = 0; i < type.length; i++) {
investment_type[i] = '"' + type[i].innerText + '"' || '"' + type[i].textContent + '"';
investment_amount[i] = amount[i].innerText || amount[i].textContent;
}
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Investeringsområde');
data.addColumn('number', 'Procent');
var rows = [];
for (var i = 2; i < investment_type.length; ++i) {
rows[i-2] =[investment_type[i], parseInt(investment_amount[i])];
}
data.addRows(rows);
var piechart_options = {
title:'Portföljfördelning',
is3D: true,
width:600,
height:400
};
var piechart = new google.visualization.PieChart(document.getElementById('chart_portfolio_division'));
piechart.draw(data, piechart_options);
}
</script>
<div class="row">
<div id="chart_portfolio_division" class="col-md-6"></div>
</div>
答案 0 :(得分:0)
只是一个错字,错过了一个逗号......
Var piechart_options = {
title:'Portföljfördelning',
is3D: true,
width:600,
height:400, // <-- comma was missing
tooltip: {
text: 'percentage'
}
};
答案 1 :(得分:0)
pieSliceText: "none"
我正在使用Google图表,并且正在处理我在选项对象中的行上方添加的相同内容,