sparkline.html.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php if($extView = $this->getExtViewFile(__FILE__)){include $extView; return helper::cd();}?>
  2. <style>
  3. .projectline {padding: 2px!important; text-align: left!important;}
  4. </style>
  5. <!--[if lte IE 8]>
  6. <?php
  7. js::import($jsRoot . 'chartjs/excanvas.min.js');
  8. ?>
  9. <![endif]-->
  10. <script>
  11. var isIE = $.zui.browser.isIE();
  12. jQuery.fn.projectLine = function(setting)
  13. {
  14. var $lines = $(this);
  15. if(isIE && $.zui.browser.ie < 9 && $lines.length > 10) return;
  16. $lines.each(function()
  17. {
  18. var $e = $(this);
  19. var options = $.extend({values: $e.attr('values')}, $e.data(), setting),
  20. height = $e.height() - 4,
  21. values = [],
  22. maxWidth = $e.width() - 4;
  23. var strValues = options.values.split(','), maxValue = 0;
  24. for(var i in strValues)
  25. {
  26. var v = parseFloat(strValues[i]);
  27. if(v != NaN)
  28. {
  29. values.push(v);
  30. maxValue = Math.max(v, maxValue);
  31. }
  32. }
  33. var scaleSteps = Math.min(maxValue, 30);
  34. var scaleStepWidth = Math.ceil(maxValue/scaleSteps);
  35. var width = Math.min(maxWidth, Math.max(10, values.length*maxWidth/30));
  36. var canvas = $e.children('canvas');
  37. if(!canvas.length)
  38. {
  39. $e.append('<canvas class="projectline-canvas"></canvas>');
  40. canvas = $e.children('canvas');
  41. if($.zui.browser.ie == 8) G_vmlCanvasManager.initElement(canvas[0]);
  42. }
  43. canvas.attr('width', width).attr('height',height);
  44. $e.data('projectLineChart', new Chart(canvas[0].getContext("2d")).Line(
  45. {
  46. labels : values,
  47. datasets:
  48. [{
  49. fillColor : $.getThemeColor('pale') || 'rgba(0,0,255,0.25)',
  50. strokeColor : 'rgba(0,0,255,1)',
  51. pointColor : $.getThemeColor('primary') || 'rgba(255,136,0,1)',
  52. pointStrokeColor : '#fff',
  53. data : values
  54. }]
  55. },
  56. {
  57. animation: !isIE,
  58. scaleOverride: true,
  59. scaleStepWidth: Math.ceil(maxValue/10),
  60. scaleSteps: 10,
  61. scaleStartValue: 0
  62. }));
  63. });
  64. }
  65. $(function(){$('.projectline').projectLine();});
  66. </script>