Hi Riccardo,
I do think I had a scope problem with 'chart', but still no love for
getState().
I'm copying most of my code in here, just removing some comments and
state options...
Thanks for helping me out on this.
// I moved most of my variables to the hight scope level for testing//
//------------------------------------------------------
<script type="text/javascript">
var allText =[];
var allTextLines = [];
var txtFile;
var chart ;
var options = {};
var data;
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
txtFile=new XMLHttpRequest();
}
else
{ // code for IE6, IE5
txtFile=new ActiveXObject("Microsoft.XMLHTTP");
}
txtFile.open("GET", "dataFile.csv", true);
txtFile.onreadystatechange = function()
{
if (txtFile.readyState == 4 && txtFile.status == 200)
{
allText = txtFile.responseText;
allTextLines = allText.split(/\r\n|\n|,|\r/);
}
}
txtFile.send(null);
google.load('visualization', '1', {'packages':['motionchart']});
google.setOnLoadCallback(drawChart);
function drawChart() {
data = new google.visualization.DataTable();
data.addColumn('string', 'Indicator');
data.addColumn('date', 'Date');
data.addColumn('number', 'Value');
var totalNumberOfLines = allTextLines.length;
for (var i =0 ; i< totalNumberOfLines ; i=i+3)
{ //hard parsing
data.addRows([[allTextLines[i].toString(),new Date (allTextLines[i
+1]),parseFloat(allTextLines[i+2])]]);
}
chart = new
google.visualization.MotionChart(document.getElementById('chart_div'));
options['width'] = 600;
options['height'] = 300;
chart.draw(data, options);
google.visualization.events.addListener(chart, 'statechange',
selectHandler);
}
function selectHandler()
{
if(!chart.getState())
{
alert(chart.getState());
}
}
</script>
--------
On Sep 29, 2:06 pm, Riccardo Govoni ☢ <
battleho...@gmail.com> wrote:
> The example you wrote is not going to work because getState() is not a
> global function, but chart.getState() should work.
>
> Are the chart and the stateHandler defined in the same scope as your snippet
> seems to suggest (that, if you put a breakpoint inside the stateHandler
> function, is 'chart' defined? ).
>
> If you could post a larger snippet showing how you create the motion chart
> and set up the listener, that would help in troubleshooting the issue.
>
> -- R.
>