page.html 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. var series = [
  7. {% for key,value in enumerate(data['statList']) %}
  8. {% if key > 0 %},{% end %}
  9. {
  10. name:'{{value['name']}}',
  11. type:'line',
  12. data:{% raw value['data']['value'] %},
  13. markPoint: {
  14. data: [
  15. {type: 'max', name: '最大值'},
  16. {type: 'min', name: '最小值'}
  17. ]
  18. },
  19. markLine: {
  20. data: [
  21. {type: 'average', name: '平均值'}
  22. ]
  23. }
  24. }
  25. {% end %}
  26. ];
  27. // 指定图表的配置项和数据
  28. var option = {
  29. title: {
  30. text: '{{data['deviceInfo']['name']}}',
  31. subtext: '数据来自{{data['setting']['farmInfo']['name']}}'
  32. },
  33. tooltip: {
  34. trigger: 'axis'
  35. },
  36. legend: {
  37. data:[{% for key,value in enumerate(data['statList']) %}{% if key > 0 %},{% end %}'{{value['name']}}'{% end %}]
  38. },
  39. toolbox: {
  40. show: true,
  41. feature: {
  42. dataZoom: {
  43. yAxisIndex: 'none'
  44. },
  45. dataView: {readOnly: false},
  46. magicType: {type: ['line', 'bar']},
  47. restore: {},
  48. saveAsImage: {}
  49. }
  50. },
  51. xAxis: {
  52. type: 'category',
  53. boundaryGap: false,
  54. data: date
  55. },
  56. yAxis: {
  57. type: 'value',
  58. axisLabel: {
  59. formatter: '{value} {{data['type']['unit']}}'
  60. }
  61. },
  62. series: series
  63. };
  64. //myChart.showLoading();
  65. // 使用刚指定的配置项和数据显示图表。
  66. //myChart.hideLoading();
  67. myChart.setOption(option, true);
  68. </script>