1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
| <template> <view class="content"> <view @click="echarts.onClick" :prop="option" :change:prop="echarts.updateEcharts" id="echarts" class="echarts"></view> <button @click="changeOption">更新数据 </button> <view> 非 APP、H5 环境不支持</view> </view> </template>
<script> export default { data() { return { option: { title: { text: 'ECharts 入门示例 ' }, tooltip: {}, legend: { data: [' 销量 '] }, xAxis: { data: [" 衬衫 ", " 羊毛衫 ", " 雪纺衫 ", " 裤子 ", " 高跟鞋 ", " 袜子 "] }, yAxis: {}, series: [{ name: ' 销量 ', type: 'bar', data: [5, 20, 36, 10, 10, 20] }] } } }, onLoad() {
}, methods: { changeOption() { const data = this.option.series[0].data data.forEach((item, index) => { data.splice(index, 1, Math.random() * 40) }) }, onViewClick(options) { console.log(options) } } } </script>
<script module="echarts" lang="renderjs"> let myChart export default { mounted() { if (typeof window.echarts === 'function') { this.initEcharts() } else { const script = document.createElement('script') script.src = 'static/echarts.js' script.onload = this.initEcharts.bind(this) document.head.appendChild(script) } }, methods: { initEcharts() { myChart = echarts.init(document.getElementById('echarts')) myChart.setOption(this.option) }, updateEcharts(newValue, oldValue, ownerInstance, instance) { myChart.setOption(newValue) }, onClick(event, ownerInstance) { ownerInstance.callMethod('onViewClick', { test: 'test' }) } } } </script>
<style> .content { display: flex; flex-direction: column; align-items: center; justify-content: center; }
.echarts { margin-top: 100px; width: 100%; height: 300px; } </style>
|