-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathchart.js-php.js
More file actions
32 lines (26 loc) · 775 Bytes
/
chart.js-php.js
File metadata and controls
32 lines (26 loc) · 775 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Will be filled with canvas
var ChartJSPHP = new Array();
// You must call this function after document.ready
function loadChartJsPhp() {
// Getting all chart.js canvas
var elements = document.querySelectorAll("[data-chartjs]");
console.log(elements);
// Looping every canvas
for (var i in elements)
{
// Escaping length and item in the loop
if (i === 'length' || i === 'item') {
continue;
}
var canvas = elements[i];
var id = canvas.id;
// Getting ctx from canvas
var ctx = canvas.getContext('2d');
// Getting values in data attributes
var htmldata = canvas.dataset;
var data = JSON.parse(htmldata.data);
var type = htmldata.chartjs;
// Creating chart and saving for later use
ChartJSPHP[id] = new Chart(ctx)[type](data);
}
};