Reputation: 5795
I am getting a reference error that data1
is not defined, my form is visible and I can see 3 circles that I have made. But when I want to update it I am getting reference error.
Here is my code for drawing which is working:
google.load('visualization', '1', {packages:['gauge']});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data1 = google.visualization.arrayToDataTable([
['Label', 'Value'],
['A', 0],
]);
var data2 = google.visualization.arrayToDataTable([
['Label', 'Value'],
['B', 0]
]);
var data3 = google.visualization.arrayToDataTable([
['Label', 'Value'],
['C', 0]
]);
var options1 = {
width: 150, height: 170,
min:0, max:200,
minorTicks: 5
};
var options2 = {
width: 150, height: 170,
min:0, max:7000,
minorTicks: 5
};
var options3 = {
width: 150, height: 170,
min:0, max:30,
minorTicks: 5
};
var chart = new google.visualization.Gauge(document.getElementById('visualization1'));
var chart2 = new google.visualization.Gauge(document.getElementById('visualization2'));
var chart3 = new google.visualization.Gauge(document.getElementById('visualization3'));
chart.draw(data1, options1);
chart2.draw(data2, options2);
chart3.draw(data3, options3);
}
And this is the function that I am using for adding a new value to data1
function changeSpeed(dir) {
console.log(dir);
data1.setValue(0, 0, dir);
chart.draw(data1, options1);
}
Probably my functions is not set correctly.
Upvotes: 1
Views: 489
Reputation: 5769
Variables options1
, options2
and options3
, also data1
, data2
and data3
are defined in local scope. You need to change you function like this:
function changeSpeed(dir, options, data) {
data.setValue(0, 0, dir);
chart.draw(data, options);
}
And use it:
changeSpeed(dir, options1, data1);
Or, you can define variables in global scope.
Upvotes: 1