graphicHome.vue 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <template>
  2. <div class="echarts_cap">
  3. <div :id="`chart_${id}`" style="height: 100%"></div>
  4. </div>
  5. </template>
  6. <script>
  7. import { pillar } from "@/utils/app-ecahrts";
  8. export default {
  9. props: {
  10. id: {
  11. type: [String, Number],
  12. default: 1,
  13. },
  14. texter: {
  15. type: Object,
  16. },
  17. },
  18. watch: {
  19. texter: function (val) {
  20. if (val) {
  21. alert(val);
  22. this.init();
  23. }
  24. },
  25. },
  26. data() {
  27. return {};
  28. },
  29. // mounted() {
  30. // if (this.texter) {
  31. // this.init();
  32. // }
  33. // },
  34. methods: {
  35. init() {
  36. let myChart = this.$echarts.init(
  37. document.getElementById(`chart_${this.id}`)
  38. ); //统计折线
  39. pillar.series[0].data = this.texter.data;
  40. pillar.title.text = this.texter.name;
  41. pillar.title.subtext = this.texter.cont;
  42. pillar.title.top = this.texter.top;
  43. pillar.series[0].color = this.texter.color;
  44. myChart.clear();
  45. myChart.setOption(pillar, true);
  46. // myChart.setOption(pillar);
  47. window.onresize = () => {
  48. myChart.resize();
  49. };
  50. },
  51. },
  52. };
  53. </script>
  54. <style lang="scss" scoped>
  55. .echarts_cap {
  56. width: 100%;
  57. height: 100%;
  58. }
  59. </style>