我正在尝试使用Google的饼图API,并让图表和图例垂直显示,图表顶部和下方的图例。我只希望图表宽度为300px,并成功地将图例移动到图表下方。然而,由于宽度太小,传说"切断"并添加左/右箭头和#'以滚动图例项目。
我试图让图例也在列表中垂直显示其项目。不是从左到右,而是从上到下,所以每个项目都可以看到。我没有在他们的文档中看到针对此特定修复程序的任何配置选项。
这是我的代码:
<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([
['Task', 'Percentage'],
['Trust Funds - 52.6%', 52.6],
['Ed & Training - 13.6%', 13.6],
['Safety, Health & Env. - 10.5%', 10.5],
['Econ Dev & Infrastructure - 9.5%', 9.5],
['Admin - 7.2%', 7.2],
['Other - 2.2%', 2.2],
['Resettlement - 2%', 2],
['Matching Gifts/UW - 1.6%', 1.6],
['Arts/Culture - 0.8%', 0.8]
]);
var options = {
colors:['#d1ae2b','#b38849','#d8a35c','#636466','#a09f9f','#31536e','#4c7ea4','#73bfe5','#88d6f8'],
pieSliceText:['none'],
legend:{position: 'bottom'},
chartArea:{left:6,top:6,width:"300px",height:"300px"}
};
var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
<div id="chart_div" style="width: 300px; height: 300px;"></div>
答案 0 :(得分:1)
Fiddle Link只需删除配置图例:{position:'bottom'},
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<div id="chart_div" style="width: 300px; height: 300px;"></div>
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Task', 'Percentage'],
['Trust Funds - 52.6%', 52.6],
['Ed & Training - 13.6%', 13.6],
['Safety, Health & Env. - 10.5%', 10.5],
['Econ Dev & Infrastructure - 9.5%', 9.5],
['Admin - 7.2%', 7.2],
['Other - 2.2%', 2.2],
['Resettlement - 2%', 2],
['Matching Gifts/UW - 1.6%', 1.6],
['Arts/Culture - 0.8%', 0.8]
]);
var options = {
width:'50px',
colors:['#d1ae2b','#b38849','#d8a35c','#636466','#a09f9f','#31536e','#4c7ea4','#73bfe5','#88d6f8'],
pieSliceText:['none'],
chartArea:{left:1,top:6,width:"100%",height:"100px"}
};
var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
chart.draw(data, options);
}