2017-02-27 62 views
0

我使用Google Charts創建餅圖。到目前爲止一切正常。我想刪除這些值,並將鼠標懸停在餡餅的切片上時保持工具提示的百分比。Google Charts Tooltip:刪除值,保留百分比

我嘗試添加:

tooltip: { 
     text: 'percentage' 
    } 

(因爲我被推薦在這裏尋找答案時做) 要我:

Var piechart_options = { 
    title:'Portföljfördelning', 
    is3D: true, 
    width:600, 
    height:400   
}; 

由於:

Var piechart_options = { 
    title:'Portföljfördelning', 
    is3D: true, 
    width:600, 
    height:400 
    tooltip: { 
     text: 'percentage' 
     }  
    }; 

遺憾的是沒有成功。當我添加這個時,圖表甚至不再繪製。有什麼建議麼?

的完整代碼:

<?php 
$result = mysqli_fetch_assoc(db_query("SELECT * FROM investments ORDER BY id DESC LIMIT 1;")); 

echo '<div style="display: none;">'; 
foreach($result as $key => $value) { 
    echo '<p class="investment_type">'. $key .'</p>'; 
    echo '<p class="investment_amount">'. $value .'</p>'; 
} 
echo '</div>' 

?> 
<script> 
var type = document.getElementsByClassName("investment_type"); 
var amount = document.getElementsByClassName("investment_amount"); 
var investment_type = []; 
var investment_amount = []; 
for(var i = 0; i < type.length; i++) { 
    investment_type[i] = '"' + type[i].innerText + '"' || '"' + type[i].textContent + '"'; 
    investment_amount[i] = amount[i].innerText || amount[i].textContent; 
} 

google.charts.setOnLoadCallback(drawChart); 
function drawChart() { 
    var data = new google.visualization.DataTable(); 
    data.addColumn('string', 'Investeringsområde'); 
    data.addColumn('number', 'Procent'); 

    var rows = []; 
    for (var i = 2; i < investment_type.length; ++i) { 
     rows[i-2] =[investment_type[i], parseInt(investment_amount[i])]; 
    } 

    data.addRows(rows); 
    var piechart_options = { 
     title:'Portföljfördelning', 
     is3D: true, 
     width:600, 
     height:400   
    }; 

    var piechart = new google.visualization.PieChart(document.getElementById('chart_portfolio_division')); 
    piechart.draw(data, piechart_options); 
} 
</script> 

<div class="row"> 
    <div id="chart_portfolio_division" class="col-md-6"></div> 
</div> 

回答

0

只是一個錯字,缺逗號......

Var piechart_options = { 
    title:'Portföljfördelning', 
    is3D: true, 
    width:600, 
    height:400, // <-- comma was missing 
    tooltip: { 
     text: 'percentage' 
    }  
}; 
+0

哇...這是尷尬:-)非常感謝你! – Elias