my-echart.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. Vue.component('my-chart', {
  2. template: '<div class="c-h100">\
  3. <div id="main" ref="main" class="c-h100"></div>\
  4. </div>',
  5. props: ['chartData'],
  6. data: function() {
  7. return {
  8. charts: null
  9. }
  10. },
  11. created: function() {
  12. },
  13. mounted: function() {
  14. this.charts = echarts.init(this.$refs.main)
  15. this.drawPie()
  16. },
  17. methods: {
  18. drawPie(){
  19. var vm = this,
  20. seriesData = []
  21. if(vm.chartData.recordType == 2) {
  22. seriesData = [{
  23. name: "收缩压",
  24. type:'line',
  25. itemStyle: {
  26. normal: {
  27. lineStyle: {
  28. color: 'rgb(102,204,204)'
  29. }
  30. }
  31. },
  32. data: vm.chartData.opinionData
  33. }, {
  34. name: "舒张压",
  35. type:'line',
  36. itemStyle: {
  37. normal: {
  38. lineStyle: {
  39. color: 'rgb(135,206,250)'
  40. }
  41. }
  42. },
  43. data: vm.chartData.opinionData2
  44. }]
  45. } else {
  46. seriesData = [{
  47. name: "血糖值",
  48. type:'line',
  49. itemStyle: {
  50. normal: {
  51. lineStyle: {
  52. color: 'rgb(102,204,204)'
  53. }
  54. }
  55. },
  56. data: vm.chartData.opinionData
  57. }]
  58. }
  59. var options = {
  60. grid: {
  61. y: 40,
  62. y2: 60
  63. },
  64. tooltip: {
  65. trigger: 'axis',
  66. position: function (pt) {
  67. return [pt[0], '10%'];
  68. }
  69. },
  70. xAxis: {
  71. type: 'category',
  72. boundaryGap: false,
  73. data: this.chartData.opinion
  74. },
  75. yAxis: {
  76. type: 'value',
  77. scale: true,
  78. name: vm.chartData.recordType == 1 ? " 单位(mmol/L)" : " 单位(mmHg)",
  79. boundaryGap: [0, '100%']
  80. },
  81. dataZoom: [{
  82. type: 'slider',
  83. start: 0,
  84. end: 100,
  85. zoomLock: false
  86. }, {
  87. start: 0,
  88. end: 10,
  89. type: 'inside',
  90. handleIcon: 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z',
  91. handleSize: '100%',
  92. handleStyle: {
  93. color: '#fff',
  94. shadowBlur: 3,
  95. shadowColor: 'rgba(0, 0, 0, 0.6)',
  96. shadowOffsetX: 2,
  97. shadowOffsetY: 2
  98. }
  99. }],
  100. series: seriesData
  101. };
  102. this.charts.setOption(options)
  103. }
  104. },
  105. watch: {
  106. chartData: function(data) {
  107. this.charts.clear();
  108. this.drawPie()
  109. }
  110. }
  111. })