1
我可以让我的谷歌图(ScatterChart)reponsive的大小简单的问题,该API增加width: 400px
和height: 200px
到内部的div,像这样:与谷歌图表
<div id="chart_div" style="position: relative;">
<div dir="ltr" style="position: relative; width: 400px; height: 200px;">
<div style="position: absolute; left: 0px; top: 0px; width: 100%; height: 100%;">
<svg width="400" height="200" aria-label="A chart." style="overflow: hidden;">
<defs id="defs">
...
你能帮我找出原因?
而且我有完全相同的代码here但对我来说这是行不通的
这里是我的html:
<div id="chart_div"></div>
CSS:
#chart_div {
width:90%;
height:20%;
}
JS:
google.load("visualization", "1", {
packages: ["corechart"],
"callback" : drawChart
});
$(window).resize(function(){
drawChart();
});
function drawChart() {
...
var options = {
title: 'Weight vs. Volume',
hAxis: {title: 'Weight (kg)', minValue: 53, maxValue: 100}, //55
vAxis: {title: 'Volume (l)'},//, minValue: 20, maxValue: 40}, //20
legend: 'none',
width: '100%',
height: '100%',
colors: ['#000000'],
series: {
1: { color: '#06b4c8' },
},
legend: {position: 'top right', textStyle: {fontSize: 8}},
chartArea: {width: '60%'},
trendlines: { 0: {//type: 'exponential',
visibleInLegend: true,
color: 'grey',
lineWidth: 2,
opacity: 0.2,
labelInLegend: 'Performance linear trendline'
}
} // Draw a trendline for data series 0.
};
var chart = new google.visualization.ScatterChart(document.getElementById('chart_div'));
chart.draw(data, options);
google.visualization.events.addListener(chart, 'ready', myReadyHandler());
function myReadyHandler() {
console.log("chartDrawn.state() before resolving:"+chartDrawn.state());
console.log("...chart is drawn");
chartDrawn.resolve();
console.log("chartDrawn.state() after resolving:"+chartDrawn.state());
}
}
看起来应该可以工作。你能否用完整的代码来更新你的帖子(或者是codepen/jsbin/jsfiddle的链接)? – asgallant