【问题标题】:Google Charts Tooltip: Remove values, keep percentageGoogle 图表工具提示:删除值,保留百分比
【发布时间】:2022-05-12 23:05:36
【问题描述】:

我正在使用 Google Charts 创建饼图。到目前为止一切正常。将鼠标悬停在饼图上时,我想删除这些值并保留工具提示上的百分比。

我尝试添加:

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>

【问题讨论】:

    标签: php charts google-visualization


    【解决方案1】:

    只是一个错字,少了一个逗号……

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

    【讨论】:

    • 哇...真尴尬 :-) 非常感谢!
    【解决方案2】:
    pieSliceText: "none"
    

    我正在使用谷歌图表并处理我在选项对象中添加的同一件事,它对我有用,

    【讨论】:

      猜你喜欢
      • 2014-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多