Note that there are some explanatory texts on larger screens.

plurals
  1. POJavaScript method begins w/ variables assigned?? very confused
    text
    copied!<p>this is my first post, but i'm excited to join this community. I have a question regarding JavaScript which I am completely stumped about. </p> <p>I'm writing a JavaScript application which pulls data from a server using ajax and adds it to a chart. I'm using Jquery and Highcharts as the framework and then writing my own JavaScript 'wrapper' around Highcharts to produce the interface.</p> <p>When the processData function get called back with the jSON response, it begins with i=1, even though i shouldn't even be initialized or even declared yet. Other variables are set as well. (I know this from using chrome developer tools to debug). This makes my loop not execute and none of my data gets added to the chart.</p> <p>I don't know how much code to show, but these are the most relevant parts. I can add more if needed.</p> <pre><code>function getData(series, min, max, numpts) { if (series === undefined) { console.log("error on getData"); return; } var request = {}; request.series = series; if (min !== undefined) { request.start = min; } //in seconds if (max !== undefined) { request.end = max; } if (numpts !== undefined) { request.numpts = numpts; } $.getJSON('/data', request, processData); return; } function processData(data) { // handle the data after it comes back from an ajax request var curSeries, chartSeries, curPoint; for (var i = 0; i &lt; data.length; i ++) { curSeries = data[i]; chartSeries = chart.get(curSeries.name); if (chartSeries === null) { //alert("oops"); chart.addSeries(curSeries); } else { for (var j = 0; j &lt; curSeries.data.length; j ++) { curPoint = curSeries.data[j]; chartSeries.addPoint(curPoint, false); } } } chart.redraw(); } </code></pre> <p>These are both methods of a class I declared called graph.</p> <p>Thanks if anyone has any ideas! -Matt P</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload