Horje
How to add link on bar for google bar chart Code Example
How to add link on bar for google bar chart
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>

<script>
    google.charts.load('current', {
        packages: ['corechart', 'bar']
    });
    google.charts.setOnLoadCallback(drawBasic);

    function drawBasic() {

        var data = google.visualization.arrayToDataTable([
            ['City', '2010 Population', { role: 'link' }],
            ['New York City, NY', 8175000, 'yout link'],
            ['Los Angeles, CA', 3792000, 'yout link'],
            ['Chicago, IL', 2695000, 'yout link'],
            ['Houston, TX', 2099000, 'yout link'],
            ['Philadelphia, PA', 1526000, 'yout link']
        ]);

        var options = {
            title: 'Population of Largest U.S. Cities',
            chartArea: {
                width: '50%'
            },
            hAxis: {
                title: 'Total Population',
                minValue: 0
            },
            vAxis: {
                title: 'City'
            }
        };

        var chart = new google.visualization.BarChart(document.getElementById('chart_div'));
        
        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, 2);
                    window.open(link,'_blank');
                }
        });

        chart.draw(data, options);
    }
</script>




Html

Related
onclick to next page in html Code Example onclick to next page in html Code Example
tag input type float number html Code Example tag input type float number html Code Example
truffle vs brownie Code Example truffle vs brownie Code Example
is header default name for html head tag Code Example is header default name for html head tag Code Example
months in german Code Example months in german Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
9