0
votes

I have to create a line chart where a few of the points have tooltips or other balloons/captions/texboxes with information about the point. They must always be displayed, not only on mouse over. Basically a google annotation chart, but with the data on the chart.

I tried the code below, which doesn't even show the tooltip as it should. Any thoughts, or should I choose a different technology? Thanks.

google.load('visualization', '1.1', { packages: ['line'] });
    google.setOnLoadCallback(drawChart);

    function drawChart() {

        var data = new google.visualization.DataTable();
        data.addColumn('number', 'Day');
        data.addColumn('number', 'Score');
        data.addColumn({type: 'string', role: 'tooltip' });

        data.addRows([
          [1, 37, 'This score occurred in Texas in 1959.'],
          [2, 30, ''],
          [3, 25, ''],        
        ]);

        var options = {
            chart: {
                title: 'Important Chart',
                subtitle: 'in millions of dollars (USD)'
            },
            width: 900,
            height: 500,
            legend: 'none',
            axes: {
                x: {
                    0: { side: 'top' }
                }
            }
        };

        var chart = new google.charts.Line(document.getElementById('line_top_x'));

        chart.draw(data, options);
    }
1

1 Answers

0
votes

You would want to use role:'annotation' instead of role: 'tooltip'. Annotation allows you to display the text without any user interaction. See the documentation on annotationRole for more info.

Working Code: http://jsfiddle.net/wkyg2brg/

google.load("visualization", "1", {packages:["corechart"]});
    google.setOnLoadCallback(drawChart);

    function drawChart() {

        var data = new google.visualization.DataTable();
        data.addColumn('number', 'Day');
        data.addColumn('number', 'Score');
        data.addColumn({type:'string', role:'annotation'});

        data.addRows([
          [1, 37, 'This score occurred in Texas in 1959.'],
          [2, 30, ''],
          [3, 25, ''],        
        ]);

        var options = {
            chart: {
                title: 'Important Chart',
                subtitle: 'in millions of dollars (USD)'
            },
            width: 900,
            height: 500,
            legend: 'none',
            axes: {
                x: {
                    0: { side: 'top' }
                }
            }
        };


        var chart = new    
          google.visualization.LineChart(document.getElementById('chart_div'));


        chart.draw(data,options);

    }