Pau*_*dam 146 html javascript charts google-visualization
// Load the Visualization API and the piechart package.
google.load('visualization', '1.0', {'packages':['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart);
// Callback that creates and populates a data table,
// instantiates the pie chart, passes in the data and
// draws it.
function drawChart() {
// Create the data table.
var data = new google.visualization.DataTable();
data.addColumn('string', 'Topping');
data.addColumn('number', 'Slices');
var myData = {
'Mushrooms': 3,
'Onions': 1,
'Olives': 1,
'Zucchini': 1,
'Pepperoni': 2
};
var rows = [];
for (element in myData) {
rows.push([element + " (" + myData[element] + ")", myData[element]])
}
data.addRows(rows);
// Set chart options
var options = {'title':'How Much Pizza I Ate Last Night',
'width':450,
'height':300};
// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
chart.draw(data, options);
}Run Code Online (Sandbox Code Playgroud)
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<div id="chart_div"></div>Run Code Online (Sandbox Code Playgroud)
在此示例中,如何删除填充或边距?
Dev*_*ant 235
通过添加和调整API文档中列出的一些配置选项,您可以创建许多不同的样式.举例来说,这里是一个版本,通过设置去除大部分多余空白的chartArea.width,以100%和chartArea.height至80%,并移动legend.position到下:
// Set chart options
var options = {'title': 'How Much Pizza I Ate Last Night',
'width': 350,
'height': 400,
'chartArea': {'width': '100%', 'height': '80%'},
'legend': {'position': 'bottom'}
};
Run Code Online (Sandbox Code Playgroud)
如果您想更多地调整它,请尝试更改这些值或使用上面链接中的其他属性.
Ama*_*irk 76
我很晚,但任何搜索此用户的用户都可以从中获得帮助.在选项中,您可以传递一个名为chartArea的新参数.
var options = {
chartArea:{left:10,top:20,width:"100%",height:"100%"}
};
Run Code Online (Sandbox Code Playgroud)
左侧和顶部选项将定义从左侧和顶部填充的数量.希望这会有所帮助.
rob*_*pim 55
我和大多数人一样来到这里同样的问题,并且震惊的是,答案都没有,甚至远程工作.
对于任何感兴趣的人,这是实际的解决方案:
... //rest of options
width: '100%',
height: '350',
chartArea:{
left:5,
top: 20,
width: '100%',
height: '350',
}
... //rest of options
Run Code Online (Sandbox Code Playgroud)
这里的关键与"左"或"顶"值无关.而是那个:
图表和图表区域的尺寸均为SET,并设置为相同值
作为我的答案的修正案.以上将确实解决"过度"填充/边距/空白问题.但是,如果您希望包含轴标签和/或图例,则需要减小图表区域的高度和宽度,使其略低于外部宽度/高度.这将"告诉"图表API有足够的空间来显示这些属性.否则它会愉快地排除它们.
Lud*_*ord 18
有一个专门用于此的主题
options: {
theme: 'maximized'
}
Run Code Online (Sandbox Code Playgroud)
来自谷歌图表文档:
目前只有一个主题可用:
'maximized' - 最大化图表区域,并在图表区域内绘制图例和所有标签。设置以下选项:
chartArea: {width: '100%', height: '100%'},
legend: {position: 'in'},
titlePosition: 'in', axisTitlesPosition: 'in',
hAxis: {textPosition: 'in'}, vAxis: {textPosition: 'in'}
Run Code Online (Sandbox Code Playgroud)
Mmy*_*low 13
像Aman Virk这样的可能性提到:
var options = {
chartArea:{left:10,top:20,width:"100%",height:"100%"}
};
Run Code Online (Sandbox Code Playgroud)
但请记住,填充和边距不会打扰你.如果您可以在不同类型的图表(如ColumnChart)和具有垂直列的图表之间切换,则需要一些余量来显示这些行的标签.
如果你拿走那个边距,那么你最终只会显示部分标签或根本没有标签.
因此,如果您只有一种图表类型,那么您可以像Arman所说的那样更改边距和填充.但如果有可能切换不改变它们.
Rob*_*Rob 13
它在文档中缺失(我使用的是版本43),但您实际上可以使用图表区域的右侧和底部属性:
var options = {
chartArea:{
left:10,
right:10, // !!! works !!!
bottom:20, // !!! works !!!
top:20,
width:"100%",
height:"100%"
}
};
Run Code Online (Sandbox Code Playgroud)
因此,可以使用完整的响应宽度和高度,并防止任何轴标签或图例被裁剪.
| 归档时间: |
|
| 查看次数: |
108816 次 |
| 最近记录: |