I'm trying to build a dynamic chart that updates every second off of this API data using CanvasJS: http://www.coincap.io/history/1day/BTC
I can't get the correct values to show. Right now it is only showing the first data set (MktCap) in the X axis. I need the data from the second set (Price). Am I messing up the keys?
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript">
window.onload = function() {
var dataPoints = [];
var chart;
$.getJSON("http://www.coincap.io/history/1day/BTC", function(data) {
$.each(data, function(key, value){
dataPoints.push({x: value[1][0], y: parseInt(value[1][1])});
});
chart = new CanvasJS.Chart("chartContainer",{
title:{
text:"Live Chart with dataPoints from External JSON"
},
data: [{
type: "line",
dataPoints : dataPoints,
}]
});
chart.render();
updateChart();
});
function updateChart() {
$.getJSON("http://www.coincap.io/history/1day/BTC", function(data) {
$.each(data, function(key, value) {
dataPoints.push({
x: parseInt(value[1][0]),
y: parseInt(value[1][1])
});
});
chart.render();
setTimeout(function(){updateChart()}, 1000);
});
}
}
</script>
<script type="text/javascript" src="https://canvasjs.com/assets/script/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
</head>
<body>
<div id="chartContainer" style="height: 300px; width: 100%;"></div>
</body>
</html>