Highchart charts Dynamically Retrieve JSON format data

Source: Internet
Author: User

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

        



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.