2013-01-08 117 views
3

我正在使用谷歌電子表格來提供給我的柱形圖。爲了讓單列成爲不同的顏色,我使用了圖表中每列的電子表格中相對列上的值爲0的方法。這給了我在圖表中每列所需的顏色差異。我現在遇到的問題是工具提示不適用於每列,並且想知道如何實現在我的代碼中正確工作。Google圖表工具提示

google.load('visualization', '1', {packages: ['corechart']}); 
</script> 
<script type="text/javascript"> 
var visualization; 

function drawVisualization() { 
    var query = new google.visualization.Query(
     'http://spreadsheets.google.com/tq?key=0AjlSK7_zXoNHdDhrU2xiaHVIQmR1WldYZm1yMTNkM3c&pub=1'); 

    // Apply query language statement. 


    // Send the query with a callback function. 
    query.send(handleQueryResponse); 
    } 

    function handleQueryResponse(response) { 
    if (response.isError()) { 
     alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage()); 
     return; 
    } 

    var data = response.getDataTable(); 
    // set the 3rd column to the "tooltip" role 
    data.setColumnProperty(3, 'role', 'tooltip'); 
    visualization = new google.visualization.ColumnChart(document.getElementById('visualization')); 
    visualization.draw(data, {legend: 'none', colors:['blue','red'],is3D:'True', isStacked:'true'}); 
    } 

google.setOnLoadCallback(drawVisualization); 
+0

如果以下答案適用於您,請點擊答案中向上/向下箭頭下方的複選標記,以便其他人可以看到這解決了您的問題。如果我的回答不夠清楚,或者您仍然有問題,請在答案中添加評論,以解釋哪些問題/哪些問題不明確。 – jmac

回答

1

選項A:

調整基礎數據使你有4列,而不是如圖3所示,與第2列具有相同的值(第一設定數據之後),爲您在當前列有3(與工具提示)。將新列2和4的setColumnProperty()用作工具提示。

選項B:使用insertColumn()

在Javascript中複製你的提示列3列2(第一數據集之後),這應該是選項A.同樣的效果,您將通過有循環複製值,或通過javascript添加相同的數據。

+0

注意:每個系列只能有一列設置爲工具提示。 – aloplop85