page.html 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <script type="text/javascript" src="{{static_url('pc/js/echarts.common.min.js')}}"></script>
  2. <script>
  3. // 基于准备好的dom,初始化echarts实例
  4. var myChart = echarts.init(document.getElementById('main'));
  5. var date = {% for key,value in enumerate(data['statList']) %}{% if key == 0 %}{% raw value['data']['time'] %}{% end %}{% end %};
  6. if (date == "") {
  7. $("#main").hide();
  8. } else {
  9. var series = [
  10. {% for key,value in enumerate(data['statList']) %}
  11. {% if key > 0 %},{% end %}
  12. {
  13. name:'{{value['name']}}',
  14. type:'line',
  15. data:{% raw value['data']['value'] %},
  16. markPoint: {
  17. data: [
  18. {type: 'max', name: '最大值'},
  19. {type: 'min', name: '最小值'}
  20. ]
  21. },
  22. markLine: {
  23. data: [
  24. {type: 'average', name: '平均值'}
  25. ]
  26. }
  27. }
  28. {% end %}
  29. ];
  30. // 指定图表的配置项和数据
  31. var option = {
  32. title: {
  33. text: '{{data['deviceInfo']['name']}}',
  34. subtext: '数据来自{{data['setting']['farmInfo']['name']}}'
  35. },
  36. tooltip: {
  37. trigger: 'axis'
  38. },
  39. legend: {
  40. data:[{% for key,value in enumerate(data['statList']) %}{% if key > 0 %},{% end %}'{{value['name']}}'{% end %}]
  41. },
  42. toolbox: {
  43. show: true,
  44. feature: {
  45. dataZoom: {
  46. yAxisIndex: 'none'
  47. },
  48. dataView: {readOnly: false},
  49. magicType: {type: ['line', 'bar']},
  50. restore: {},
  51. saveAsImage: {}
  52. }
  53. },
  54. xAxis: {
  55. type: 'category',
  56. boundaryGap: false,
  57. data: date
  58. },
  59. yAxis: {
  60. type: 'value',
  61. axisLabel: {
  62. formatter: '{value} {{data['type']['unit']}}'
  63. }
  64. },
  65. series: series
  66. };
  67. //myChart.showLoading();
  68. // 使用刚指定的配置项和数据显示图表。
  69. //myChart.hideLoading();
  70. myChart.setOption(option, true);
  71. $("#main").show();
  72. }
  73. </script>