gpt4 book ai didi

google-visualization - Google饼图图例显示

转载 作者:行者123 更新时间:2023-12-04 08:52:57 25 4
gpt4 key购买 nike

我正在尝试使用Google的饼图API,并使图表和图例垂直显示,图表在顶部,图例在下面。我只希望图表宽度为300像素,并且已成功将图例移至图表下方。但是,由于宽度太小,图例会“切掉”并添加左/右箭头和#来滚动图例项。

我正在尝试使图例也在列表中垂直显示其项目。不是从左到右,而是从上到下,以便可以看到每个项目。我在他们的文档中没有看到针对此特定修复程序的任何配置选项。

这是我的代码:

<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>

最佳答案

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);
}

关于google-visualization - Google饼图图例显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11229488/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com