【问题标题】:Google Chart HTML Tooltip displays html textGoogle Chart HTML Tooltip 显示 html 文本
【发布时间】:2014-02-18 17:19:16
【问题描述】:

我在选项中指定了 HTML 工具,但它仍然在工具提示中呈现 HTML 文本,而不是 HTML 的结果。我该如何解决这个问题,以便它呈现 HTML 结果?

我创建了一个数据视图并像这样设置列:

projectView.setColumns([0,1,3,{
    type:'string',
    role:'tooltip',
    calc:function(dt,row){
        var date = dt.getFormattedValue(row,0);
        var totalErrors = dt.getFormattedValue(row,3);
        var percent = Math.round((dt.getValue(row,3)/dt.getValue(row,1))*100);  
        return '<div><b>'+ date +'</b><br><b>Error Percent: </b>' + percent + '<br><b>Total Errors: </b>' + totalErrors + '</div>';
    }
}]);

而且选项是这样的:

var options = {
    width:850,
    height:375,
    chartArea: {width: '70%', height: '70%',left: 40,top:25},
    hAxis:{format:'MM/dd/yy'},
    vAxis:{logScale:false},         
    series:{0:{type:'line'},1:{type:'area'}},
    tooltip: { isHtml: true }};

然后我绘制图表:

var projectChart = new google.visualization.ComboChart(document.getElementById('project_chart_div'));
projectChart.draw(projectView, options);

【问题讨论】:

    标签: html charts tooltip google-visualization dataview


    【解决方案1】:

    在视图的计算列中将html 属性指定为true

    projectView.setColumns([0,1,3,{
        type:'string',
        role:'tooltip',
        properties: {
            html: true
        },
        calc:function(dt,row){
            var date = dt.getFormattedValue(row,0);
            var totalErrors = dt.getFormattedValue(row,3);
            var percent = Math.round((dt.getValue(row,3)/dt.getValue(row,1))*100);  
            return '<div><b>'+ date +'</b><br><b>Error Percent: </b>' + percent + '<br><b>Total Errors: </b>' + totalErrors + '</div>';
        }
    }]);
    

    【讨论】:

    • 我一直在努力解决这个问题,但我在任何地方都找不到这个选项“properties: { html: true }”。甚至在这里:developers.google.com/chart/interactive/docs/… 我使用的是 "p: {html: true}" 但这对我不起作用。你拯救了我的一天。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-28
    相关资源
    最近更新 更多