2017-03-17 50 views
0

我正在研究一個項目,我想要在加載google地圖時禁用或修改縮放因子(默認縮放)。但我無法做到。當活動開始時,它顯示以下;在加載Google圖表時禁用縮放因子

enter image description here

碼是:

<html> 
<head> 
    <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> 
    <script type="text/javascript"> 
     google.charts.load('current', { 
    callback: function() { 
    drawChart(); 
    window.addEventListener('resize', drawChart, false); 
    }, 
    packages:['corechart'] 
}); 

function drawChart() { 
    var data = google.visualization.arrayToDataTable([ 
    ['Year', 'Sales', 'Expenses', 'Profit'], 
    ['2014', 1000, 400, 200], 
    ['2015', 1170, 460, 250], 
    ['2016', 660, 1120, 300], 
    ['2017', 1030, 540, 350] 
    ]); 

    var options = { 
    animation:{ 
     duration: 1000, 
     easing: 'linear', 
     startup: true 
    }, 
    height: 600, 
    theme: 'material', 
    title: 'Company Performance' 
    }; 

    var chart = new google.visualization.ColumnChart(document.getElementById('columnchart_material')); 
    chart.draw(data, options); 
} 
    </script> 
</head> 
<body> 
<div id="columnchart_material" style="width: 900px; height: 500px;"></div> 
</body> 
</html> 

示例:我想要適合300 * 300尺寸的完整圖表。

回答

0

圖表將填充容器

看到下面的工作段的寬度......

google.charts.load('current', { 
 
    callback: function() { 
 
    drawChart(); 
 
    window.addEventListener('resize', drawChart, false); 
 
    }, 
 
    packages:['corechart'] 
 
}); 
 

 
function drawChart() { 
 
    var data = google.visualization.arrayToDataTable([ 
 
    ['Year', 'Sales', 'Expenses', 'Profit'], 
 
    ['2014', 1000, 400, 200], 
 
    ['2015', 1170, 460, 250], 
 
    ['2016', 660, 1120, 300], 
 
    ['2017', 1030, 540, 350] 
 
    ]); 
 

 
    var options = { 
 
    animation:{ 
 
     duration: 1000, 
 
     easing: 'linear', 
 
     startup: true 
 
    }, 
 
    height: 600, 
 
    theme: 'material', 
 
    title: 'Company Performance' 
 
    }; 
 

 
    var chart = new google.visualization.ColumnChart(document.getElementById('columnchart_material')); 
 
    chart.draw(data, options); 
 
}
#columnchart_material{ 
 
    width: 300px; 
 
}
<script src="https://www.gstatic.com/charts/loader.js"></script> 
 
<div id="columnchart_material"></div>

+0

你在容器上設置一個寬度是多少?或者如果寬度改變,圖表將需要重新繪製... – WhiteHat

+0

寬度恆定。 (300 * 300)。 – Humty

+0

在容器可見之前繪製圖表嗎? – WhiteHat