Dies ist das erste Mal, dass ich versuche, Json zu benutzen Ich kann dieses Problem nicht lösen Der Controller
gib dieses json zurück
[
{"ID":1,"month":"september","sale":120},
{"ID":2,"month":"september","sale":122}
]
Das Diagramm benötigt Daten in diesem Format
data: [
["Firefox", 45.0],
["IE", 26.8],
{
name: "Chrome",
y: 12.8,
}]
Wie bekomme ich die Daten, die der Controller im richtigen Format an das Diagramm zurückgibt?
Diese Lösung funktioniert nicht
var data=[];
var uri = "api/chartapi";
/* $(function () {
$.getJSON(uri)
.done(function (json) {
$.each(data, function (name, score) { {
data.push({
name: name,
y: score
});
}
});
});
});
Antworten:
0 für die Antwort № 1Vielleicht einfach das Format auf js analysieren? So was: http://jsfiddle.net/3bQne/992/
var data = [],
json = [{
"ID": 1,
"month": "september",
"sale": 120
}, {
"ID": 2,
"month": "september",
"sale": 122
}];
for (var i = 0; i < json.length; i++) {
data.push({
name: json[i].month,
id: json[i].ID,
y: json[i].sale
});
}
var chart = new Highcharts.Chart({
chart: {
renderTo: "container",
type: "pie"
},
series: [{
data: data
}]
});