chart.html.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <div class='milestone-chart' id='milestoneChart'>
  2. <div class='chart-canvas scrollbar-hover'>
  3. <div class='chart-wrapper'>
  4. <canvas width='400' height='120' data-responsive='true'></canvas>
  5. </div>
  6. </div>
  7. <div class='chart-unit'><?php echo "({$lang->execution->workHour})";?></div>
  8. <div class='chart-legend'>
  9. <span class="barline line-pv">PV</span>
  10. <span class="barline line-ev">EV</span>
  11. <span class="barline line-ac">AC</span>
  12. </div>
  13. </div>
  14. <style>
  15. .milestone-chart {position: relative}
  16. .milestone-chart .chart-canvas {overflow: auto; max-width: 1002px}
  17. .milestone-chart .chart-wrapper {background: none; padding: 15px 0 0 0}
  18. .milestone-chart .chart-unit {position: absolute; left: 10px; top: 0;}
  19. .milestone-chart .chart-legend {position: absolute; right: 5px; top: 0;}
  20. .milestone-chart .barline {padding-left: 20px; position: relative; display: inline-block; line-height: 20px}
  21. .milestone-chart .barline + .barline {margin-left: 5px}
  22. .milestone-chart .barline:before {content: ' '; display: block; position: absolute; top: 8px; left: 0; width: 16px; height: 3px; background: #0c64eb}
  23. .milestone-chart .barline.line-ev:before {background: rgb(0, 218, 136)}
  24. .milestone-chart .barline.line-ac:before {background: rgb(255, 145, 0)}
  25. </style>
  26. <script>
  27. function initMilestoneChart()
  28. {
  29. var data =
  30. {
  31. labels: <?php echo json_encode($charts['labels'])?>,
  32. datasets: [
  33. {
  34. label: 'PV',
  35. color: '#0c64eb',
  36. pointColor: '#0c64eb',
  37. pointStrokeColor: '#0c64eb',
  38. pointHighlightStroke: '#0c64eb',
  39. fillColor: 'rgba(0,106,241, .07)',
  40. pointHighlightFill: '#fff',
  41. data: <?php echo $charts['PV']?>
  42. },
  43. {
  44. label: 'EV',
  45. color: 'rgb(0, 218, 136)',
  46. pointColor: 'rgb(0, 218, 136)',
  47. pointStrokeColor: 'rgb(0, 218, 136)',
  48. pointHighlightStroke: 'rgb(0, 218, 136)',
  49. fillColor: 'rgb(0, 218, 136, .07)',
  50. pointHighlightFill: '#fff',
  51. data: <?php echo $charts['EV']?>
  52. },
  53. {
  54. label: 'AC',
  55. color: 'rgb(255, 145, 0)',
  56. pointColor: 'rgb(255, 145, 0)',
  57. pointStrokeColor: 'rgb(255, 145, 0)',
  58. pointHighlightStroke: 'rgb(255, 145, 0)',
  59. fillColor: 'rgb(255, 145, 0, .07)',
  60. pointHighlightFill: '#fff',
  61. data: <?php echo $charts['AC']?>
  62. }]
  63. };
  64. var betterWidth = data.labels.length * 15;
  65. var renderChart = function()
  66. {
  67. var $chart = $('#milestoneChart');
  68. var $wrapper = $chart.find('.chart-wrapper');
  69. var $canvas = $chart.find('canvas');
  70. var $chartCanvas = $chart.find('.chart-canvas');
  71. if (betterWidth > 400)
  72. {
  73. var updateWrapperSize = function()
  74. {
  75. $wrapper.hide();
  76. $chartCanvas.css('max-width', 'initial');
  77. var maxWidth = $chartCanvas.width();
  78. $chartCanvas.css('max-width', maxWidth);
  79. $chart.toggleClass('has-scrollbar', maxWidth < betterWidth);
  80. $wrapper.show();
  81. };
  82. updateWrapperSize();
  83. $(window).on('resize', updateWrapperSize);
  84. $wrapper.css('min-width', betterWidth);
  85. $canvas.attr(
  86. {
  87. width: betterWidth,
  88. height: Math.min(200, Math.floor(betterWidth / 4))
  89. });
  90. }
  91. $canvas.lineChart(data,
  92. {
  93. animation: betterWidth < 400,
  94. pointDotStrokeWidth: 1,
  95. pointDotRadius: 2,
  96. datasetStrokeWidth: 2,
  97. datasetFill: false,
  98. datasetStroke: true,
  99. scaleShowBeyondLine: true,
  100. responsive: true,
  101. bezierCurve: false,
  102. scaleFontColor: '#838A9D',
  103. tooltipXPadding: 10,
  104. tooltipYPadding: 10,
  105. multiTooltipTitleTemplate: '<%= label %> <?php echo $lang->execution->workHour;?> /h',
  106. multiTooltipTemplate: '<%if (datasetLabel){%><%=datasetLabel%>: <%}%><%= value %>',
  107. });
  108. }
  109. setTimeout(renderChart, betterWidth > 200 ? 100 : 10);
  110. }
  111. initMilestoneChart();
  112. </script>