This is my first post, but I am happy to join this community. I have a question regarding JavaScript with which I am completely at a dead end.
I am writing a JavaScript application that retrieves data from a server using ajax and adds it to a chart. I use Jquery and Highcharts as a framework, and then create my own JavaScript wrapper around Highcharts to create an interface.
When the processData function receives a callback with a jSON response, it starts with i = 1, although I do not even have to be initialized or even declared. Other variables are also set. (I know this from using chrome debugging tools). This causes my loop to fail, and not one of my data is added to the chart.
I donβt know how much code to display, but these are the most important parts. If necessary, I can add more.
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;
}
if (max !== undefined) {
request.end = max;
}
if (numpts !== undefined) {
request.numpts = numpts;
}
$.getJSON('/data', request, processData);
return;
}
function processData(data) {
var curSeries,
chartSeries,
curPoint;
for (var i = 0; i < data.length; i ++) {
curSeries = data[i];
chartSeries = chart.get(curSeries.name);
if (chartSeries === null) {
chart.addSeries(curSeries);
} else {
for (var j = 0; j < curSeries.data.length; j ++) {
curPoint = curSeries.data[j];
chartSeries.addPoint(curPoint, false);
}
}
}
chart.redraw();
}
These are both methods of class I declared as graph.
Thanks if anyone has any ideas! -Matt P
source
share