I am trying to display a bar chart using chart.js.
The data JSON is in another file called barchart.txt from where I am reading it in my function. It looks like the format of data is incorrect because when I put alert on first line of function, even that doesn't work.
Both barchart.txt and Default.aspx are at same location.
barchart.txt
{
labels: ["January", "February", "March", "April", "May", "June", "July"],
datasets: [
{
label: "Dataset Testing",
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)',
'rgba(255, 206, 86, 0.2)',
'rgba(75, 192, 192, 0.2)',
'rgba(153, 102, 255, 0.2)',
'rgba(255, 159, 64, 0.2)'
],
borderColor: [
'rgba(255,99,132,1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)',
'rgba(75, 192, 192, 1)',
'rgba(153, 102, 255, 1)',
'rgba(255, 159, 64, 1)'
],
borderWidth: 1,
data: [65, 59, 80, 81, 56, 55, 40],
}
]
}
Default.aspx
<html>
<canvas id="mybarChart1"></canvas>
</html>
<script>
$.getJSON("barchart.txt", function (data)
{
alert("here");
var ctx = document.getElementById("mybarChart1");
var myChart = new Chart(ctx, {
type: 'bar',
data: data,
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
}
}
});
});
</script>