Zing Feed Get Data From Rest Api
I am getting a json data from rest api and i want to use it as input to ZingFeed.
Solution 1:
The issue here is the nature of asynchronous functions in Javascript. Returning the data from AJAX doesn't work the way you've attempted above. You can read more about it here.
Here's a working solution.
I work on the ZingChart team. Let me know if you have other questions about the ZingChart library.
<!DOCTYPE html><html><head><metacharset="ISO-8859-1"><title>Insert title here</title><scriptsrc='http://cdn.zingchart.com/zingchart.min.js'></script><scriptsrc="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script></head><body><script>var chartData = {
"type":"line",
"refresh": {
"type": "feed",
"transport": "js",
"url": "feed()",
"interval": 200
},
"series":[
{
"values":[]
}
]
};
window.onload = function() {
zingchart.render({
id: "chartDiv",
data: chartData,
height: 600,
width: "100%"
});
};
window.feed = function(callback) {
$.ajax({
type: "GET",
dataType: "json",
headers: {
Accept: "application/json",
"Access-Control-Allow-Origin": "*"
},
url: "/PerformanceMonitor/showProcessUsage/chrome",
success: function (data) {
var mem = data.mem.size/10000;
var tick = {
plot0: parseInt(mem)
};
callback(JSON.stringify(tick));
}
});
};
</script><divid="processInfo"></div><divid='chartDiv'></div></body>
Post a Comment for "Zing Feed Get Data From Rest Api"