pretty new to javascript.
Im trying to read a JSON file located on my localhost (http://localhost:8080/jsonData.json) and format it to be displayed using Chart.js.
Here is my JSON File:
[{"date": "1/02/16", "price":15.25},
{"date":"29/01/16", "price":15.35},
{"date":"28/01/16", "price":15.1}]
and my html file which will display the chart:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Test Chart</title>
<script src="javascript/Chart.js"></script>
</head>
<body>
<canvas id="mycanvas" width="400" height="400"></canvas>
<script>
$.getJSON( "http://localhost:8080/jsonData.json", function( data ) {
var chartjsData = [];
var labels = [];
$.each( data, function( key, val ) {
labels.push(key);
chartjsData.push(val);
});
var lineChartData = {
labels : labels,
datasets : [{
fillColor : "rgba(220,280,220,0.5)",
strokeColor : "rgba(220,220,220,1)",
data : chartjsData
}]
};
var myLine = new Chart(document.getElementById("mycanvas").getContext("2d")).Line(lineChartData);
});
</script>
</body>
</html>
basically when i run it i just get a blank screen with nothing displayed so I'm guessing its something to do with how I'm parsing the file, any help would be appreciated.