我有這個google chart on a my website。現在是散點圖,但我希望所有類型圖表的解決方案。 例如,如果您使用700-px範圍的窗口加載站點,則圖表尺寸無法響應:圖表太寬。 以下是我正在使用的代碼。響應Google圖表的最佳做法
你能幫我嗎?
感謝
HTML:
<div id="chart_div"></div>
CSS:
#chart_div {
width:100%;
height:20%;
}
JS:
var options = {
title: 'Weight of pro surfer vs. Volume of his pro model',
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: 'Linear trendline\n(Performance)'
}
} // 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() {
chartDrawn.resolve(); }
編輯:看來,在div #chart_div
有正確的大小(我的一個等用CSS),但這個div裏面的圖表不會調整其大小...保持鎖定與 看到圖像:
謝謝您的回答,但現在我不是事件想着適應圖表大小時調整windown的大小,但只需在網站加載時正確設置即可,以便在頁面加載時正確獲取尺寸。 Resigin窗口將是下一步。你明白嗎 ? – Louis 2014-08-28 09:55:23
如果您將CSS容器div的尺寸設置爲百分比,那麼圖表的大小將根據其容器的大小動態設置。 – asgallant 2014-08-28 12:32:47
這就是我的想法,這正是我正在做的事情:我已經用html更新了這個問題,所以你可以看到。例如,如果將寬度值從100%更改爲20%,則不會更改圖形的大小。你在這裏重複:http://boardlineapp.com/#faq – Louis 2014-08-28 14:45:27