widget2chart.js 1.9 KB

1
  1. void 0!==document.addEventListener&&document.addEventListener("DOMContentLoaded",function(){"undefined"!=typeof Chart?[].forEach.call(document.querySelectorAll("div.chartjs"),function(e){var t,a;t="undefined"!=typeof chartjs_colors?chartjs_colors:"undefined"!=typeof chartjs_colors_json?JSON.parse(chartjs_colors_json):{fillColor:"rgba(151,187,205,0.5)",strokeColor:"rgba(151,187,205,0.8)",highlightFill:"rgba(151,187,205,0.75)",highlightStroke:"rgba(151,187,205,1)",data:["#B33131","#B66F2D","#B6B330","#71B232","#33B22D","#31B272","#2DB5B5","#3172B6","#3232B6","#6E31B2","#B434AF","#B53071"]},a="undefined"!=typeof chartjs_config?chartjs_config:"undefined"!=typeof chartjs_config_json?JSON.parse(chartjs_config_json):{Bar:{animation:!1},Doughnut:{animateRotate:!1},Line:{animation:!1},Pie:{animateRotate:!1},PolarArea:{animateRotate:!1}};var r=e.getAttribute("data-chart"),n=JSON.parse(e.getAttribute("data-chart-value"));if(n&&n.length&&r){e.innerHTML="";var o=document.createElement("canvas");o.height=e.getAttribute("data-chart-height"),e.appendChild(o);var i=document.createElement("div");i.setAttribute("class","chartjs-legend"),e.appendChild(i);var l,h=o.getContext("2d"),d=new Chart(h);if("bar"!=r)for(l=0;l<n.length;l++)n[l].color=t.data[l],n[l].highlight=t.data[l];if("bar"==r||"line"==r){var s={datasets:[{label:"",fillColor:t.fillColor,strokeColor:t.strokeColor,highlightFill:t.highlightFill,highlightStroke:t.highlightStroke,data:[]}],labels:[]};for(l=0;l<n.length;l++)n[l].value&&(s.labels.push(n[l].label),s.datasets[0].data.push(n[l].value));i.innerHTML=""}"bar"==r?d.Bar(s,a.Bar):"line"==r?d.Line(s,a.Line):i.innerHTML="polar"==r?d.PolarArea(n,a.PolarArea).generateLegend():"pie"==r?d.Pie(n,a.Pie).generateLegend():d.Doughnut(n,a.Doughnut).generateLegend()}}):"undefined"!=typeof console&&console.log("ERROR: You must include chart.min.js on this page in order to use Chart.js")});