Highchart charts Dynamically Retrieve JSON format data
Highchart line chart code
$ (Function () {var chartLine = new Highcharts. Chart ({chart: {type: 'line ',RenderTo: 'container2'}, Title: {text: 'result of comparison between the amount paid last month and the bill amount of this month '}, subtitle: {text: ''}, xAxis: {categories: []}, yAxis: {title: {text: 'unit (yuan) '}}, tooltip: {enabled: false, formatter: function () {return''+ This. series. name +'
'+ This. x + ':' + this. y + '°c ';}}, plotOptions: {line: {dataLabels: {enabled: true}, enableMouseTracking: false }}, series: [{name: 'repayment amount of the previous month', data: []}, {name: 'consumption amount of the current month', data: []}); function getFormLine () {return $ http. get ("/billsDetail/twoMonthChartData "). success (function (response) {// set the value for the chartChartLine. series [0]. setData (response. data. lastMonth); chartLine. series [1]. setData (response. data. thisMonth); chartLine. xAxis [0]. setCategories (eval (response. data. categorys ));}). Error (function (response) {$ log. debug ("request timeout or network fault! An error occurred while obtaining the list! ")}) ;}Getformline ();});
JSON code of the backend
public JSONObject listLastMonthAndThismonthBillsData() { JSONObject json =new JSONObject(); List
categorys =new ArrayList
(); List
lastMonthData=new ArrayList
(); List
thisMonthData=new ArrayList
(); String sql="select lastmonth_repayment,thismonth_bill,period from credit_card_bills order by period asc " ; List
resultdata = billsDetailDao.list(sql); for(JSONObject dataItem:resultdata) { categorys.add(dataItem.getString("period")); lastMonthData.add(dataItem.getDouble("lastmonth_repayment")); thisMonthData.add(dataItem.getDouble("thismonth_bill")); } json.put("categorys",categorys); json.put("lastMonth",lastMonthData); json.put("thisMonth",thisMonthData); return json; }
HTML code