Your code fails because of this:
var chartDataInput = chartDataResults.scores;
chartDataResults
is an array by your declaration, not an object. According to the amDocs you could pass chartDataResults
directly, given that it is in the correct format, eg [{title:"sample 1",value:130},{title:"sample 2",value:26}];
.
If so - try to replace:
var chartDataInput = chartDataResults.scores;
//this all works:
var chartData = chartDataInput;
with
var chartData = chartDataResults;
If you chartDataResults array is not in the correct format, you need to construct it in that loop. Something like:
for (var i=0 ; i < results.length ; i++) {
if (results[i][searchField] == searchVal) {
var aResult = new Object();
aResult.title = results[i].title; // or results[i]['title']
aResult.value = parseInt(results[i].value); // or results[i]['value']
chartDataResults.push(aResult);
}
}
I am speculating that in your json objects you have .title
and .value
. If not - replace them accordingly. If you're not sure :) what properties they have - print them to the console and inspect them.