chart.util.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. $(function () {
  2. var energyPieChart //饼图对象
  3. var pieCharts
  4. var energyLineChart //线图对象
  5. var lineCharts
  6. Highcharts.setOptions({
  7. lang: {
  8. printChart: "打印图表",
  9. downloadPNG: "导出PNG格式图片",
  10. downloadJPEG: "导出 JPEG格式图片",
  11. downloadPDF: "导出 PDF文档",
  12. downloadSVG: "导出 SVG矢量图片",
  13. contextButtonTitle: "打印和导出",
  14. },
  15. global: { useUTC: false },
  16. })
  17. pieCharts = {
  18. chart: {
  19. plotBackgroundColor: null,
  20. plotBorderWidth: null,
  21. plotShadow: false,
  22. renderTo: "pieContainer",
  23. },
  24. title: {
  25. text: "产品耗电占比",
  26. },
  27. tooltip: { pointFormat: "{series.name}: <b>{point.percentage:.1f}%</b>" },
  28. plotOptions: { pie: { allowPointSelect: true, cursor: "pointer", dataLabels: { enabled: false }, showInLegend: true } },
  29. series: [],
  30. }
  31. lineCharts = {
  32. chart: {
  33. type: "spline",
  34. renderTo: "lineContainer",
  35. },
  36. title: {
  37. text: "产品耗电明细",
  38. },
  39. xAxis: {
  40. type: "datetime",
  41. tickInterval: 3600 * 1000 * 24 * 3,
  42. gridLineWidth: 1, //默认是0,即在图上没有纵轴间隔线
  43. //自定义x刻度上显示的时间格式,根据间隔大小,以下面预设的小时/分钟/日的格式来显示
  44. dateTimeLabelFormats: {
  45. day: "%d",
  46. },
  47. },
  48. yAxis: {
  49. min: 0,
  50. title: {
  51. text: "电量(kW.h)",
  52. },
  53. },
  54. tooltip: {
  55. crosshairs: true,
  56. crosshairs: [
  57. {
  58. // 设置准星线样式
  59. width: 1,
  60. color: "green",
  61. },
  62. {
  63. width: 1,
  64. color: "#006cee",
  65. dashStyle: "longdashdot",
  66. zIndex: 100,
  67. },
  68. ],
  69. shared: true, // 是否共享提示,也就是X一样的所有点都显示出来
  70. useHTML: true, // 是否使用HTML编辑提示信息
  71. headerFormat: "<small>{point.key}</small><table>",
  72. pointFormat: '<tr><td style="color: {series.color}">{series.name}: </td>' + '<td style="text-align: right"><b>{point.y}</b></td></tr>',
  73. footerFormat: "</table>",
  74. valueDecimals: 2, // 数据值保留小数位数
  75. xDateFormat: "%Y-%m-%d",
  76. },
  77. plotOptions: {
  78. series: {
  79. connectNulls: true,
  80. },
  81. },
  82. series: [],
  83. }
  84. var monthLineCharts = {
  85. chart: {
  86. type: "spline",
  87. renderTo: "lineContainer",
  88. },
  89. title: {
  90. text: "产品耗电明细",
  91. },
  92. xAxis: {
  93. categories: [],
  94. },
  95. yAxis: {
  96. min: 0,
  97. title: {
  98. text: "电量(kW.h)",
  99. },
  100. },
  101. tooltip: {
  102. crosshairs: true,
  103. crosshairs: [
  104. {
  105. // 设置准星线样式
  106. width: 1,
  107. color: "green",
  108. },
  109. {
  110. width: 1,
  111. color: "#006cee",
  112. dashStyle: "longdashdot",
  113. zIndex: 100,
  114. },
  115. ],
  116. shared: true, // 是否共享提示,也就是X一样的所有点都显示出来
  117. useHTML: true, // 是否使用HTML编辑提示信息
  118. headerFormat: "<small>{point.key}月</small><table>",
  119. pointFormat: '<tr><td style="color: {series.color}">{series.name}: </td>' + '<td style="text-align: right"><b>{point.y}</b></td></tr>',
  120. footerFormat: "</table>",
  121. valueDecimals: 2, // 数据值保留小数位数
  122. xDateFormat: "%Y-%m-%d",
  123. },
  124. plotOptions: {
  125. series: {
  126. connectNulls: true,
  127. },
  128. },
  129. series: [],
  130. }
  131. fillPieChart = function (data) {
  132. var series = []
  133. series.push(data)
  134. pieCharts.series = series
  135. energyPieChart = new Highcharts.Chart(pieCharts)
  136. }
  137. fillLineChart = function (data) {
  138. var series = []
  139. $.each(data.series, function () {
  140. var tpe = null
  141. for (var i = 0; i < this.data.length; i++) {
  142. tpe = this.data[i][1]
  143. if (tpe != null) {
  144. break
  145. }
  146. }
  147. if (tpe == null) {
  148. var map = {}
  149. map["name"] = this.name
  150. map["data"] = []
  151. series.push(map)
  152. } else {
  153. series.push(this)
  154. }
  155. })
  156. lineCharts.series = series
  157. energyLineChart = new Highcharts.Chart(lineCharts)
  158. }
  159. fillMonthLineChart = function (data) {
  160. monthLineCharts.xAxis.categories = data.categories
  161. monthLineCharts.series = data.series
  162. console.log(data.series)
  163. energyLineChart = new Highcharts.Chart(monthLineCharts)
  164. }
  165. })