AdityaK
AdityaK

Reputation: 339

How to make horizontal bar graph label values as hyperlink using google chart api

 var options = {

May be vAxis have some properties for making label value as hyperlink

                     vAxis: { textStyle: { color: '#005500', fontSize: '13', fontName:  'Arial'} },
                     width: 700,
                     height: 400,
                     bar: { groupWidth: '15%' },
                     isStacked: true,
                     chartArea: { left: 150, width: 700 }

                 };

Upvotes: 2

Views: 1819

Answers (1)

asgallant
asgallant

Reputation: 26340

You cannot create hyperlinks from the axis labels, but you can use a "click" event handler for your chart that detects clicks on the axis labels and then acts as if a link was clicked:

google.visualization.events.addListener(chart, 'click', function (e) {
    // match the id of the axis label
    var match = e.targetID.match(/hAxis#0#label#(\d+)/);
    if (match && match.length) {
        var row = parseInt(match[1]);
        // use row to fetch any data you need from the DataTable to construct your hyperlink, eg:
        var label = data.getValue(row, 0);
        // then construct your URL and use it however you want, eg:
        var url = 'http://www.google.com/search?q=' + label;
        window.location = url;
    }
});

Upvotes: 4

Related Questions