chartjs.init.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. /******/ (function() { // webpackBootstrap
  2. var __webpack_exports__ = {};
  3. /*!********************************************!*\
  4. !*** ./resources/js/pages/chartjs.init.js ***!
  5. \********************************************/
  6. /*
  7. Template Name: Skote - Admin & Dashboard Template
  8. Author: Themesbrand
  9. Website: https://themesbrand.com/
  10. Contact: themesbrand@gmail.com
  11. File: ChartJs init Js File
  12. */
  13. function getChartColorsArray(chartId) {
  14. if (document.getElementById(chartId) !== null) {
  15. var colors = document.getElementById(chartId).getAttribute("data-colors");
  16. if (colors) {
  17. colors = JSON.parse(colors);
  18. return colors.map(function (value) {
  19. var newValue = value.replace(" ", "");
  20. if (newValue.indexOf(",") === -1) {
  21. var color = getComputedStyle(document.documentElement).getPropertyValue(newValue);
  22. if (color){
  23. color = color.replace(" ", "");
  24. return color;
  25. }
  26. else return newValue;;
  27. } else {
  28. var val = value.split(',');
  29. if (val.length == 2) {
  30. var rgbaColor = getComputedStyle(document.documentElement).getPropertyValue(val[0]);
  31. rgbaColor = "rgba(" + rgbaColor + "," + val[1] + ")";
  32. return rgbaColor;
  33. } else {
  34. return newValue;
  35. }
  36. }
  37. });
  38. }
  39. }
  40. }
  41. !function ($) {
  42. "use strict";
  43. var ChartJs = function ChartJs() {};
  44. ChartJs.prototype.respChart = function (selector, type, data, options) {
  45. Chart.defaults.global.defaultFontColor = "#9295a4", Chart.defaults.scale.gridLines.color = "rgba(166, 176, 207, 0.1)"; // get selector by context
  46. var ctx = selector.get(0).getContext("2d"); // pointing parent container to make chart js inherit its width
  47. var container = $(selector).parent(); // enable resizing matter
  48. $(window).resize(generateChart); // this function produce the responsive Chart JS
  49. function generateChart() {
  50. // make chart width fit with its container
  51. var ww = selector.attr('width', $(container).width());
  52. switch (type) {
  53. case 'Line':
  54. new Chart(ctx, {
  55. type: 'line',
  56. data: data,
  57. options: options
  58. });
  59. break;
  60. case 'Doughnut':
  61. new Chart(ctx, {
  62. type: 'doughnut',
  63. data: data,
  64. options: options
  65. });
  66. break;
  67. case 'Pie':
  68. new Chart(ctx, {
  69. type: 'pie',
  70. data: data,
  71. options: options
  72. });
  73. break;
  74. case 'Bar':
  75. new Chart(ctx, {
  76. type: 'bar',
  77. data: data,
  78. options: options
  79. });
  80. break;
  81. case 'Radar':
  82. new Chart(ctx, {
  83. type: 'radar',
  84. data: data,
  85. options: options
  86. });
  87. break;
  88. case 'PolarArea':
  89. new Chart(ctx, {
  90. data: data,
  91. type: 'polarArea',
  92. options: options
  93. });
  94. break;
  95. } // Initiate new chart or Redraw
  96. }
  97. ; // run function - render chart at first load
  98. generateChart();
  99. }, //init
  100. ChartJs.prototype.init = function () {
  101. //creating lineChart
  102. var LinechartLinechartColors = getChartColorsArray("lineChart");
  103. if (LinechartLinechartColors) {
  104. var lineChart = {
  105. labels: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October"],
  106. datasets: [{
  107. label: "Sales Analytics",
  108. fill: true,
  109. lineTension: 0.5,
  110. backgroundColor: LinechartLinechartColors[0],
  111. borderColor: LinechartLinechartColors[1],
  112. borderCapStyle: 'butt',
  113. borderDash: [],
  114. borderDashOffset: 0.0,
  115. borderJoinStyle: 'miter',
  116. pointBorderColor: LinechartLinechartColors[1],
  117. pointBackgroundColor: "#fff",
  118. pointBorderWidth: 1,
  119. pointHoverRadius: 5,
  120. pointHoverBackgroundColor: LinechartLinechartColors[1],
  121. pointHoverBorderColor: "#fff",
  122. pointHoverBorderWidth: 2,
  123. pointRadius: 1,
  124. pointHitRadius: 10,
  125. data: [65, 59, 80, 81, 56, 55, 40, 55, 30, 80]
  126. }, {
  127. label: "Monthly Earnings",
  128. fill: true,
  129. lineTension: 0.5,
  130. backgroundColor: LinechartLinechartColors[2],
  131. borderColor: LinechartLinechartColors[3],
  132. borderCapStyle: 'butt',
  133. borderDash: [],
  134. borderDashOffset: 0.0,
  135. borderJoinStyle: 'miter',
  136. pointBorderColor: LinechartLinechartColors[3],
  137. pointBackgroundColor: "#fff",
  138. pointBorderWidth: 1,
  139. pointHoverRadius: 5,
  140. pointHoverBackgroundColor: LinechartLinechartColors[3],
  141. pointHoverBorderColor: "#eef0f2",
  142. pointHoverBorderWidth: 2,
  143. pointRadius: 1,
  144. pointHitRadius: 10,
  145. data: [80, 23, 56, 65, 23, 35, 85, 25, 92, 36]
  146. }]
  147. };
  148. var lineOpts = {
  149. scales: {
  150. yAxes: [{
  151. ticks: {
  152. max: 100,
  153. min: 20,
  154. stepSize: 10
  155. }
  156. }]
  157. }
  158. };
  159. this.respChart($("#lineChart"), 'Line', lineChart, lineOpts);
  160. } //donut chart
  161. var DoughnutchartColors = getChartColorsArray("doughnut");
  162. if (DoughnutchartColors) {
  163. var donutChart = {
  164. labels: ["Desktops", "Tablets"],
  165. datasets: [{
  166. data: [300, 210],
  167. backgroundColor: DoughnutchartColors,
  168. hoverBackgroundColor: DoughnutchartColors,
  169. hoverBorderColor: "#fff"
  170. }]
  171. };
  172. this.respChart($("#doughnut"), 'Doughnut', donutChart);
  173. } //Pie chart
  174. var PiechartColors = getChartColorsArray("pie");
  175. if (PiechartColors) {
  176. var pieChart = {
  177. labels: ["Desktops", "Tablets"],
  178. datasets: [{
  179. data: [300, 180],
  180. backgroundColor: PiechartColors,
  181. hoverBackgroundColor: PiechartColors,
  182. hoverBorderColor: "#fff"
  183. }]
  184. };
  185. this.respChart($("#pie"), 'Pie', pieChart);
  186. } //barchart
  187. var BarchartColors = getChartColorsArray("bar");
  188. if (BarchartColors) {
  189. var barChart = {
  190. labels: ["January", "February", "March", "April", "May", "June", "July"],
  191. datasets: [{
  192. label: "Sales Analytics",
  193. backgroundColor: BarchartColors[0],
  194. borderColor: BarchartColors[0],
  195. borderWidth: 1,
  196. hoverBackgroundColor: BarchartColors[1],
  197. hoverBorderColor: BarchartColors[1],
  198. data: [65, 59, 81, 45, 56, 80, 50, 20]
  199. }]
  200. };
  201. var barOpts = {
  202. scales: {
  203. xAxes: [{
  204. barPercentage: 0.4
  205. }]
  206. }
  207. };
  208. this.respChart($("#bar"), 'Bar', barChart, barOpts);
  209. } //radar chart
  210. var RadarchartColors = getChartColorsArray("radar");
  211. if (RadarchartColors) {
  212. var radarChart = {
  213. labels: ["Eating", "Drinking", "Sleeping", "Designing", "Coding", "Cycling", "Running"],
  214. datasets: [{
  215. label: "Desktops",
  216. backgroundColor: RadarchartColors[0],
  217. borderColor: RadarchartColors[1],
  218. pointBackgroundColor: RadarchartColors[1],
  219. pointBorderColor: "#fff",
  220. pointHoverBackgroundColor: "#fff",
  221. pointHoverBorderColor: RadarchartColors[1],
  222. data: [65, 59, 90, 81, 56, 55, 40]
  223. }, {
  224. label: "Tablets",
  225. backgroundColor: RadarchartColors[2],
  226. borderColor: RadarchartColors[3],
  227. pointBackgroundColor: RadarchartColors[3],
  228. pointBorderColor: "#fff",
  229. pointHoverBackgroundColor: "#fff",
  230. pointHoverBorderColor: RadarchartColors[3],
  231. data: [28, 48, 40, 19, 96, 27, 100]
  232. }]
  233. };
  234. this.respChart($("#radar"), 'Radar', radarChart);
  235. } //Polar area chart
  236. var PolarAreachartColors = getChartColorsArray("polarArea");
  237. if (PolarAreachartColors) {
  238. var polarChart = {
  239. datasets: [{
  240. data: [11, 16, 7, 18],
  241. backgroundColor: PolarAreachartColors,
  242. label: 'My dataset',
  243. // for legend
  244. hoverBorderColor: "#fff"
  245. }],
  246. labels: ["Series 1", "Series 2", "Series 3", "Series 4"]
  247. };
  248. this.respChart($("#polarArea"), 'PolarArea', polarChart);
  249. }
  250. }, $.ChartJs = new ChartJs(), $.ChartJs.Constructor = ChartJs;
  251. }(window.jQuery), //initializing
  252. function ($) {
  253. "use strict";
  254. $.ChartJs.init();
  255. }(window.jQuery);
  256. /******/ })()
  257. ;