Add tooltips to a Google Line Chart with multiple data series - with simplified test case and screenshot

前端 未结 1 1292
春和景丽
春和景丽 2020-12-19 06:32

I have a Google Line Chart with 2 data series - Row A and Row B:

\"enter

相关标签:
1条回答
  • 2020-12-19 07:05

    You can use a DataView to create the tooltip columns for you. This code snippet will dynamically create a tooltip column in the DataView for every data series:

    var columns = [0];
    for (var i = 1; i < x.getNumberOfColumns(); i++) {
        columns.push(i);
        columns.push({
            type: 'string',
            properties: {
                role: 'tooltip'
            },
            calc: (function (j) {
                return function (dt, row) {
                    return dt.getColumnLabel(j) + ': x=' + dt.getValue(row, 0) + ' y=' + dt.getValue(row, j)
                }
            })(i)
        });
    }
    var view = new google.visualization.DataView(x);
    view.setColumns(columns);
    

    See the working example here: http://jsfiddle.net/asgallant/xWwxP/

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