简体   繁体   中英

Highcharts - load json data

I am working on a new project and using highchart for chart creation . I created a json file with some data from database:

[{"date": "2012-02-23", "number": 2}, {"date": "2012-02-21", "number": 4]

How do i can add this data to Highcharts->Chart->Series->Data ?

Find the code below. This displays the column chart for the data present in the JSON.

 <html>
    <head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript"></script>
    <script src="http://code.highcharts.com/highcharts.js" type="text/javascript"></script>
    <script type="text/javascript">
    jQuery(document).ready(function(){
            var data=[{"date": "2012-02-23", "number": 2}, {"date": "2012-02-21", "number": 4}];
            var chart = new Highcharts.Chart(
              {
                chart:{
                    renderTo: "container", // the div id where you want to dispaly the chart
                    type: 'column',        // type of chart as colum chart, it can be anything-'bar','pie','column' etc.
                    height: 300
                },
                title: {
                    text: "Numbers on two different dates"
                },
                xAxis: {
                    categories: [data[0]["date"],data[1]["date"]]
                },
                yAxis: {
                    title: {
                        text: 'Numbers on date'
                    }
                },
                series: [{name:"numbers",data:[data[0]["number"],data[1]["number"]]}]
            }  
        );          
    });
    </script>
    </head>
    <body>
    <div id="container">
    </div>
    </body>
    </html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM