123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- <template>
- <div :id="chartId" style="width: 420px;height: 160px" />
- </template>
- <script>
- import echarts from 'echarts'
- export default {
- name: 'Hello',
- props: {
- chartId: {
- type: String,
- default: 'myChart'
- },
- option: {
- type: Object,
- default() {
- return {}
- }
- }
- },
- data() {
- return {
- msg: 'Welcome to Your Vue.js App'
- }
- },
- watch: {
- option(newValue, oldValue) {
- this.drawLine()
- }
- },
- mounted() {
- this.drawLine()
- },
- methods: {
- drawLine() {
- // 基于准备好的dom,初始化echarts实例
- const myChart = echarts.init(document.getElementById(this.chartId))
- // 绘制图表
- myChart.setOption(this.option)
- }
- }
- }
- </script>
- <style>
- </style>
|