my-echart.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. {
  22. name: vm.chartData.recordType == 1 ? "血糖值" : "收缩压",
  23. type:'line',
  24. itemStyle: {
  25. normal: {
  26. lineStyle: {
  27. color: 'rgb(102,204,204)'
  28. }
  29. }
  30. },
  31. data: vm.chartData.opinionData
  32. }
  33. ]
  34. if(vm.chartData.recordType == 2) {
  35. seriesData.push({
  36. name: "舒张压",
  37. type:'line',
  38. itemStyle: {
  39. normal: {
  40. lineStyle: {
  41. color: 'rgb(135,206,250)'
  42. }
  43. }
  44. },
  45. data: vm.chartData.opinionData2
  46. })
  47. }
  48. var options = {
  49. grid: {
  50. y: 40,
  51. y2: 60
  52. },
  53. tooltip: {
  54. trigger: 'axis',
  55. position: function (pt) {
  56. return [pt[0], '10%'];
  57. }
  58. },
  59. xAxis: {
  60. type: 'category',
  61. boundaryGap: false,
  62. data: this.chartData.opinion
  63. },
  64. yAxis: {
  65. type: 'value',
  66. scale: true,
  67. name: vm.chartData.recordType == 1 ? " 单位(mmol/L)" : " 单位(mmHg)",
  68. boundaryGap: [0, '100%']
  69. },
  70. dataZoom: [{
  71. type: 'slider',
  72. start: 0,
  73. end: 100,
  74. zoomLock: false
  75. }, {
  76. start: 0,
  77. end: 10,
  78. type: 'inside',
  79. 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',
  80. handleSize: '100%',
  81. handleStyle: {
  82. color: '#fff',
  83. shadowBlur: 3,
  84. shadowColor: 'rgba(0, 0, 0, 0.6)',
  85. shadowOffsetX: 2,
  86. shadowOffsetY: 2
  87. }
  88. }],
  89. series: seriesData
  90. };
  91. this.charts.setOption(options)
  92. }
  93. },
  94. watch: {
  95. chartData: function(data) {
  96. this.drawPie()
  97. }
  98. }
  99. })