Created
July 20, 2018 20:28
-
-
Save alissonbovenzo/fa5dc40abfff67b2d88115708ae2562f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var canvas = document.getElementById("barChart"); | |
var ctx = canvas.getContext('2d'); | |
// Global Options: | |
Chart.defaults.global.defaultFontColor = 'black'; | |
Chart.defaults.global.defaultFontSize = 16; | |
var data = { | |
labels: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"], | |
datasets: [{ | |
label: "Stock A", | |
fill: false, | |
lineTension: 0.1, | |
backgroundColor: "rgba(225,0,0,0.4)", | |
borderColor: "red", // The main line color | |
borderCapStyle: 'square', | |
borderDash: [], // try [5, 15] for instance | |
borderDashOffset: 0.0, | |
borderJoinStyle: 'miter', | |
pointBorderColor: "black", | |
pointBackgroundColor: "white", | |
pointBorderWidth: 1, | |
pointHoverRadius: 8, | |
pointHoverBackgroundColor: "yellow", | |
pointHoverBorderColor: "brown", | |
pointHoverBorderWidth: 2, | |
pointRadius: 4, | |
pointHitRadius: 10, | |
// notice the gap in the data and the spanGaps: true | |
data: [65, 59, 80, 81, 56, 55, 40, ,60,55,30,78], | |
spanGaps: true, | |
}, { | |
label: "Stock B", | |
fill: true, | |
lineTension: 0.1, | |
backgroundColor: "rgba(167,105,0,0.4)", | |
borderColor: "rgb(167, 105, 0)", | |
borderCapStyle: 'butt', | |
borderDash: [], | |
borderDashOffset: 0.0, | |
borderJoinStyle: 'miter', | |
pointBorderColor: "white", | |
pointBackgroundColor: "black", | |
pointBorderWidth: 1, | |
pointHoverRadius: 8, | |
pointHoverBackgroundColor: "brown", | |
pointHoverBorderColor: "yellow", | |
pointHoverBorderWidth: 2, | |
pointRadius: 4, | |
pointHitRadius: 10, | |
// notice the gap in the data and the spanGaps: false | |
data: [10, 20, 60, 95, 64, 78, 90,,70,40,70,89], | |
spanGaps: false, | |
} | |
] | |
}; | |
// Notice the scaleLabel at the same level as Ticks | |
var options = { | |
scales: { | |
yAxes: [{ | |
ticks: { | |
beginAtZero:true | |
}, | |
scaleLabel: { | |
display: true, | |
labelString: 'Moola', | |
fontSize: 20 | |
} | |
}] | |
} | |
}; | |
// Chart declaration: | |
var myBarChart = new Chart(ctx, { | |
type: 'line', | |
data: data, | |
options: options | |
}); | |
setTimeout(function(){ | |
data.datasets[0].hidden = true; | |
console.log(myBarChart.update({ | |
duration: 800, | |
easing: 'easeOutBounce' | |
})) | |
},3000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment