I want to add data to Morris bar-chart via ajax. Following is the json which i get in ajax success
[{"x":"2014-10-02","y":"1"},{"x":"2014-10-19","y":"1"},{"x":"2014-10-20","y":"1"},{"x":"2014-11-13","y":"1"}]
following is the js code
var chart = Morris.Bar({
element : 'normal-bar-graph',
data : [{
"x" : null,
"y" : null
}],
xkey : 'x',
ykeys : ['y'],
labels : ['Added']
});
$.ajax({
type: "POST",
url: "some_url",
data: {'user_report':[k,v]},
success: function(html)
{
if(html == "error")
{
alert('error');
}
else
{
chart.setData(html);
}
hide_loading();
}
});
am using /morris/raphael.2.1.0.min.js
and /morris/morris.min.js
.
The chart.setData(html);
functionality does not work as said in the documentation of morris.
thank in advance. please point me out if any error made.
have also made a jsbin if that can help: morris
Remove the quotes. setData
expects an array. When you use quotes, it converts that into a string instead of array.
Like this : chart.setData([{ "y": "2006", "a": 100, "b": 90 },{ "y": "2006", "a": 100, "b": 90 }]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With