select tag
I've got the function select_value()
<select id="data" onChange="select_value()">
<option value="['car', 7],['jeep', 2],['taxi', 1]">aaa</option>
<option value="['car', 9],['taxi', 1]">bbb</option>
</select>
I can't call the select_value() function inside google chart...
my script
function select_value() {
var stringPie = document.getElementById('data').value;
}
google chart
var data = new google.visualization.DataTable();
data.addColumn('string', 'Cartype');
data.addColumn('number', 'Amount');
var stringPie = document.getElementById('data').value; // <==
var arrPie = eval("[" + stringPie + "]");
data.addRows(arrPie);
the chart always stuck on the first option value of select tag...
The select element contains values like:
that appear to be data for multiple rows. You are converting it to an array using eval, which is a very poor strategy.
To avoid eval, convert the string to an appropriate structure using split or JSON.parse, e.g.
Markup:
Script:
JSON.parse is handy because like eval, you can easily specify different types (e.g. string, number) but avoid many of the pitfalls of eval.
Untested, but should work.