google charts HTML annotations

前端 未结 1 1700
盖世英雄少女心
盖世英雄少女心 2021-01-20 22:49

With Google Charts, it is possible to have text annotations. I however require an image to be displayed.

Here\'s a JS fiddle (adapted from someone else\'s code) showing

相关标签:
1条回答
  • 2021-01-20 23:49

    After some experimentation, I determined that you can add images to the annotations, but only to the annotationText column.

    In order to make the HTML annotations work, you must do two things: first, set the annotationText column's html property to true, and then set the chart's tooltip.isHtml property to true, like this:

    var data = new google.visualization.DataTable();
    data.addColumn('string', 'Name');
    data.addColumn('number', 'Value');
    data.addColumn({type: 'string', role: 'annotation'});
    data.addColumn({type: 'string', role: 'annotationText', p: {html: true}});
    
    data.addRows([
        ['Foo', 53, 'Foo text', '<img src="bar.png"> Foo description'],
        ['Bar', 71, 'Bar text', 'Bar description'],
        ['Baz', 36, 'Baz text', 'Baz description'],
        ['Cad', 42, 'Cad text', 'Cad description'],
        ['Qud', 87, 'Qud text', 'Qud description'],
        ['Pif', 64, 'Pif text', 'Pif description']
    ]);
    
    var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
    chart.draw(data, {
        height: 400,
        width: 600,
        tooltip: {
            isHtml: true
        }
    });
    

    See working example here: http://jsfiddle.net/asgallant/7w2Hz/

    0 讨论(0)
提交回复
热议问题