Hi I have the following script
The page can also be seen in action here
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml2/DTD/xhtml1-strict.dtd">
<!-- Version: 1.0.0 -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Flot Examples</title>
<link href="layout.css" rel="stylesheet" type="text/css">
<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="../excanvas.min.js"></script><![endif]-->
<script language="javascript" type="text/javascript" src="../jquery.js"></script>
<script language="javascript" type="text/javascript" src="../jquery.flot.js"></script>
</head>
<body onLoad="myFunction()">
<a href="javascript:printing()">Show All Coverafdedge</a>
Show: </div>
<p><span id="x">0</span>, <span id="y">0</span></p>
<p><input id="enableTooltip" type="checkbox">Enable tooltip</p>
<script type="text/javascript">
var datasets = [];
var xmlhttp;
function loadXMLDoc(url,cfunc){
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=cfunc;
xmlhttp.open("GET",url,true);
xmlhttp.send();
}
function myFunction(){
loadXMLDoc("parsers.json",handleXML);
}
var checkState = function(xmlhttp, callback) {
//document.write(xmlhttp.readyState);
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
callback();
} else {
// Check back again 1 sec later
setTimeout(checkState, 1000);
}
};
function handleXML() {
checkState(xmlhttp, function() {
var txt=xmlhttp.responseText;
datasets = [];
var datasetsCounter =0;
var secondPos = 0;
var aPosition = 0;
var currentCharacterLocation =0;
var textLeft =txt;
do
{
aPosition = textLeft.indexOf("#");
secondPos = textLeft.indexOf(";");
evaluedText = textLeft.substring(aPosition+1,secondPos);
datasets[currentCharacterLocation] = eval("(" + evaluedText + ")");
currentCharacterLocation++;
textLeft = textLeft.substring(secondPos + 1);
}
while (textLeft.indexOf("#") > -1);
});
}
function printing(){
for(var g =0; g < datasets.length; g++ ){
document.write(datasets[g].cover.data + "__");
}
}
$(function () {
var d1 = [];
var d2 = datasets[0].cover.data;
// a null signifies separate line segments
var d3 = [[0, 12], [7, 12], null, [7, 2.5], [12, 2.5]];
$.plot($("#placeholder"), [ d1, d2, d3 ]);
});
</script>
</body>
</html>
Now to my problem that I have with the variable "datasets", if I for example try to print out "datasets[0].cover.data" (Like I do in my function printing(), I can do that (Try yourself clicking on the link on that page). But when I try to use the variable inside the
"var d2 = datasets[0].cover.data", I get the error that its datasets[0].cover.data is not defined :S
Anyone know what I am doing wrong here? =)
Thanks