|
| 1 | +<template> |
| 2 | + <div class="container"> |
| 3 | + <div id="main"></div> |
| 4 | + <div id="main1" ref="elRef"></div> |
| 5 | + </div> |
| 6 | +</template> |
| 7 | + |
| 8 | +<script lang="ts"> |
| 9 | + // https://vega.github.io/vega/usage/ |
| 10 | + import { defineComponent, onMounted, ref, unref } from 'vue'; |
| 11 | + import { useECharts } from '/@/hooks/web/useECharts'; |
| 12 | + import echarts from 'echarts'; |
| 13 | +
|
| 14 | + export default defineComponent({ |
| 15 | + name: 'DemoChart', |
| 16 | + setup() { |
| 17 | + const elRef = ref<any>(null); |
| 18 | + const { setOptions } = useECharts(elRef); |
| 19 | +
|
| 20 | + // onMounted(() => { |
| 21 | + // const el = unref(elRef); |
| 22 | + // if (!el || !unref(el)) return; |
| 23 | + // const chart = echarts.init(el); |
| 24 | +
|
| 25 | + // window.addEventListener('resize', () => { |
| 26 | + // chart!.resize(); |
| 27 | + // }); |
| 28 | + // // removeResizeFn = removeEvent; |
| 29 | + // var option = { |
| 30 | + // title: { |
| 31 | + // text: 'ECharts entry example', |
| 32 | + // }, |
| 33 | + // tooltip: {}, |
| 34 | + // legend: { |
| 35 | + // data: ['Sales'], |
| 36 | + // }, |
| 37 | + // xAxis: { |
| 38 | + // data: ['shirt', 'cardign', 'chiffon shirt', 'pants', 'heels', 'socks'], |
| 39 | + // }, |
| 40 | + // yAxis: {}, |
| 41 | + // series: [ |
| 42 | + // { |
| 43 | + // name: 'Sales', |
| 44 | + // type: 'bar', |
| 45 | + // data: [5, 20, 36, 10, 10, 20], |
| 46 | + // }, |
| 47 | + // ], |
| 48 | + // }; |
| 49 | + // chart && chart.setOption(option as any); |
| 50 | + // }); |
| 51 | + onMounted(() => { |
| 52 | + var myChart = echarts.init(elRef.value); |
| 53 | + // specify chart configuration item and data |
| 54 | + var option = { |
| 55 | + title: { |
| 56 | + text: 'ECharts entry example', |
| 57 | + }, |
| 58 | + tooltip: {}, |
| 59 | + legend: { |
| 60 | + data: ['Sales'], |
| 61 | + }, |
| 62 | + xAxis: { |
| 63 | + data: ['shirt', 'cardign', 'chiffon shirt', 'pants', 'heels', 'socks'], |
| 64 | + }, |
| 65 | + yAxis: {}, |
| 66 | + series: [ |
| 67 | + { |
| 68 | + name: 'Sales', |
| 69 | + type: 'bar', |
| 70 | + data: [5, 20, 36, 10, 10, 20], |
| 71 | + }, |
| 72 | + ], |
| 73 | + }; |
| 74 | + setOptions(option); |
| 75 | + // use configuration item and data specified to show chart |
| 76 | + // myChart.setOption(option); |
| 77 | + // window.addEventListener('resize', () => { |
| 78 | + // myChart.resize(); |
| 79 | + // }); |
| 80 | + }); |
| 81 | +
|
| 82 | + return { elRef }; |
| 83 | + }, |
| 84 | + }); |
| 85 | +</script> |
| 86 | +<style> |
| 87 | + .container { |
| 88 | + width: 100%; |
| 89 | + } |
| 90 | +
|
| 91 | + #main, |
| 92 | + #main1 { |
| 93 | + width: 40%; |
| 94 | + height: 300px; |
| 95 | + } |
| 96 | +</style> |
0 commit comments