5.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <template>
  2. <div id="myChartold5" style="width: 100%; height: 100%;"></div>
  3. </template>
  4. <script>
  5. import { oldPersonOldHealth } from '../../api'
  6. export default {
  7. name: "MzColumnCharts",
  8. data() {
  9. return {
  10. dataArr: [],
  11. colorArr: [
  12. { color1: '#ff2311', color2: 'rgba(255, 128, 125, 0.1)' },
  13. { color1: '#2222ff', color2: 'rgba(161, 154, 255, 0.1)' },
  14. { color1: '#00c8ff', color2: 'rgba(154, 235, 255, 0.1)' },
  15. { color1: '#ff00fd', color2: 'rgba(255, 159, 242, 0.1)' }
  16. ],
  17. myChart: null
  18. }
  19. },
  20. methods: {
  21. async draw() {
  22. const result = await oldPersonOldHealth({}, 'POST');
  23. this.dataArr = result;
  24. this.myChart = this.$echarts.init(document.getElementById('myChartold5'));
  25. this.myChart.setOption({
  26. xAxis: {
  27. type: 'category',
  28. data: this.dataArr.map((item) => item.label),
  29. axisLine: {
  30. show: true,
  31. lineStyle: {
  32. color: '#3075e2'
  33. }
  34. },
  35. splitLine:{
  36. show:false
  37. },
  38. axisLabel: {
  39. show: true,
  40. textStyle: {
  41. color: 'white'
  42. }
  43. }
  44. },
  45. yAxis: {
  46. type: 'value',
  47. axisLine: {
  48. show: true,
  49. lineStyle: {
  50. color: '#3075e2'
  51. }
  52. },
  53. splitLine:{
  54. show:false
  55. },
  56. axisLabel: {
  57. show: true,
  58. textStyle: {
  59. color: 'white'
  60. }
  61. }
  62. },
  63. series: [{
  64. type: 'bar',
  65. barWidth:'40',
  66. data: this.dataArr.map((item) => item.value),
  67. itemStyle: {
  68. color: (params) => {
  69. return new this.$echarts.graphic.LinearGradient(
  70. 0, 0, 0, 1,
  71. [
  72. {offset: 0, color: this.colorArr[ params.dataIndex ].color1},
  73. {offset: 1, color: this.colorArr[ params.dataIndex ].color2}
  74. ]
  75. )
  76. }
  77. },
  78. label: {
  79. show: true,
  80. position: 'top',
  81. color: '#fff',
  82. fontSize: 16
  83. }
  84. }]
  85. });
  86. }
  87. },
  88. mounted() {
  89. this.draw();
  90. }
  91. }
  92. </script>
  93. <style scoped>
  94. </style>