1

I want to click a rectangle in the Google tree control and set a value in another part of the page.

I am using the following code, but nothing is happening as an alert.

    tree.draw(data, {
        minColor: '#f00',
        midColor: '#ddd',
        maxColor: '#0d0',
        headerHeight: 15,
        fontColor: 'black',
        showScale: true
    });
}


// this code does not work

function myOnClickFunction(){
    TreeMap.getSelection();
    var txt = TreeMap.getValue(0, TreeMap.getSelection());

    alert(txt);

}
google.visualization.events.addListener(TreeMap, 'select', myOnClickFunction);
// end of none working code
</script>
</head>

<body>
    <div id="chart_div" style="width: 500px; height: 900px;"></div>
</body>
</html>

1 Answer 1

0

First of all, you named the variable for your TreeMap visualization tree in your drawing function, but try to create an event handler using a variable called TreeMap. Ssecond, your event handler is not in scope for your tree variable. Third, the getSelection method does not return a column index by itself, so you can't use the output directly in the getValue method call. Change the variable name and move the event handler inside your drawing function, and adjust the code inside the event handler like this:

function myOnClickFunction(){
    var selection = tree.getSelection();
    if (selection.length) {
        var txt = data.getValue(selection[0].row, selection[0].column);
        alert(txt);
    }
}
google.visualization.events.addListener(tree, 'select', myOnClickFunction);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.