google_analytics.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. (function ($) {
  2. $.fn.extend( {
  3. googleAnalyticsChart: function() {
  4. var $chart = $(this);
  5. var ctx = $chart.get(0).getContext("2d");
  6. var $data = $chart.find('.chart-data');
  7. var $dataItems = $data.find('.chart-data-item');
  8. var labels = [];
  9. var data = [];
  10. $dataItems.each(function() {
  11. labels.push($(this).data('date'));
  12. data.push($(this).data('value'));
  13. });
  14. var chart = new Chart(ctx).Line({
  15. labels: labels,
  16. datasets: [
  17. {
  18. fillColor: $chart.find('.chart-fillColor').css('color'),
  19. strokeColor: $chart.find('.chart-strokeColor').css('color'),
  20. pointColor: $chart.find('.chart-pointColor').css('color'),
  21. pointHighlightFill: $chart.find('.chart-pointHighlightFill').css('color'),
  22. responsive: true,
  23. data: data
  24. }
  25. ]
  26. }, {
  27. scaleGridLineColor: $chart.find('.chart-scaleGridLineColor').css('color'),
  28. scaleLineColor: $chart.find('.chart-scaleLineColor').css('color'),
  29. scaleFontColor: $chart.find('.chart-scaleFontColor').css('color')
  30. });
  31. var updateChartColors = function(chart) {
  32. for (var i = 0; i < chart.datasets.length; ++i) {
  33. chart.datasets[i]['fillColor'] = $chart.find('.chart-fillColor').css('color');
  34. chart.datasets[i]['strokeColor'] = $chart.find('.chart-strokeColor').css('color');
  35. chart.datasets[i]['pointColor'] = $chart.find('.chart-pointColor').css('color');
  36. chart.datasets[i]['pointHighlightFill'] = $chart.find('.chart-pointHighlightFill').css('color');
  37. }
  38. chart.scale['gridLineColor'] = $chart.find('.chart-scaleGridLineColor').css('color');
  39. chart.scale['lineColor'] = $chart.find('.chart-scaleLineColor').css('color');
  40. chart.scale['textColor'] = $chart.find('.chart-scaleFontColor').css('color');
  41. chart.update();
  42. };
  43. $(document).on('theme:changed', function() {
  44. updateChartColors(chart);
  45. });
  46. }
  47. });
  48. })(jet.jQuery);