alrite after searching and creating new function, i have realize that morris.js cannot parse the JSON object.
first change the servlet into:
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
/* Execution of jSON Chart */
Analytics show = new Analytics();
List<JSONObject> json = show.getStatisticPesanan();
out.print(js.toJSONString());
} finally {
out.close();
}
}
then it will shows the right JSON object like this:
[{"1":"2013-10-12","2":3},{"1":"2013-11-16","2":2},{"1":"2013-12-23","2":4},{"1":"2014-02-11","2":10}]
then parse the JSON object into
new Morris.Bar({
// ID of the element in which to draw the chart.
element: 'pesanan-chart-area',
data: $.parseJSON(json_data),
xkey: 'tahun',
ykeys: ['jml'],
labels: ['Jumlah'],
smooth: false
});
we NEED to use function $.parseJSON
to make the graph shows correctly, otherwise the graph will show undefined
.
i hope this will help someone.