How to add links in google chart api

前端 未结 5 777
南方客
南方客 2021-01-01 22:43

Can I add links in google chart api?

For example,

\"enter

How could I

5条回答
  •  悲哀的现实
    2021-01-01 23:17

    The simple way of adding link to google barchart;

    var data = google.visualization.arrayToDataTable([
         ['Element', 'Density', { role: 'style' }, { role: 'link' } ],
         ['Copper', 8.94, '#b87333', '/your/custom/link' ],
         ['Silver', 10.49, 'silver', '/your/custom/link' ],
         ['Gold', 19.30, 'gold', '/your/custom/link' ],
         ['Platinum', 21.45, 'color: #e5e4e2', '/your/custom/link' ]
      ]);
    

    and before chart.draw;

     google.visualization.events.addListener(chart, 'select', function (e) {
                var selection = chart.getSelection();
                    if (selection.length) {
                        var row = selection[0].row;
                        let link =data.getValue(row, 3);
                        location.href = link;
                    }
            });
    

提交回复
热议问题