I have this .json
:
[ { "id": "bitcoin", "name": "Bitcoin", "symbol": "BTC", "rank": "1", "price_usd": "9433.76", "price_btc": "1.0", "24h_volume_usd": "7381970000.0", "market_cap_usd": "160572613853", "available_supply": "17021062.0", "total_supply": "17021062.0", "max_supply": "21000000.0", "percent_change_1h": "0.46", "percent_change_24h": "-0.6", "percent_change_7d": "3.38", "last_updated": "1525742073" } ]
And I need the value of price_usd
to be added to my highcharts , I have a function that makes the Ajax request that does not if I pick up the value of price_usd
and then charge in the event of the highcharts , the code I have is the following:
Highcharts.chart('btc', {
chart: {
type: 'spline',
animation: Highcharts.svg, // don't animate in old IE
marginRight: 10,
events: {
load: requestData
}
},
title: {
text: 'Bitcoin'
},
xAxis: {
type: 'datetime',
tickPixelInterval: 150
},
yAxis: {
title: {
text: 'Value'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
formatter: function () {
return '<b>' + this.series.name + '</b><br/>' +
Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) + '<br/>' +
Highcharts.numberFormat(this.y, 2);
}
},
legend: {
enabled: false
},
exporting: {
enabled: false
},
series: [
{
name: 'mentions',
data: []
}
]
});
function requestData() {
$.ajax({
url: 'APIcriptomonedas/datosAPI/bitcoin.json',
type: "GET",
dataType: "json",
data : {username : "demo"},
success: function(data) {
chart.addSeries({
name: "mentions",
data: data.price_usd
});
},
cache: false
});