javascript - Returning JSON file with cURL to use data in a HighCharts stock chart -
i'm trying free json source of oil price data highcharts stockchart different server curl.
the code have far follows:
<div id="container" style="width:100%; height:400px;"> <?php $ch = curl_init('https://www.quandl.com/api/v1/datasets/chris/ice_b1.json'); $data = curl_exec($ch); curl_close($ch); ?> <script> $(function () { $.getjson('$data', function (data) { // create chart $('#container').highcharts('stockchart', { rangeselector : { selected : 1 }, title : { text : description }, series : [{ name : name data : data } }] }); }); }); </script> </div>
but dump raw json browser window rather making beautiful chart.
any appreciated!
you trying use php curl
, jquery getjson
@ same time, think bit confused.
curl executed server, , in way prints results whenever gets it, not store result in $data
because need initialise curl wait response curl_setopt($curl, curlopt_returntransfer, 1);
. if save result in php variable $data
, variable not available in javascript, since javascript executed on clients machine , not on server. fix
<php echo "<script> data = ".$data."; </script>"; ?>
which not pretty work. still not work getjson
function because function expects url json data , not expect json data parameter..
to make story short, can use getjson
function below , delete php code , should work, think want.
$(function () { $.getjson('https://www.quandl.com/api/v1/datasets/chris/ice_b1.json', function (data) { // create chart $('#container').highcharts('stockchart', { rangeselector : { selected : 1 }, title : { text : description }, series : [{ name : name data : data }] }); }); });
because getjson
tried curl
function: json
data url provide , store in variable called data
.
Comments
Post a Comment