| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <template>
- <div :id="uuid" :style="style"></div>
- </template>
- <script>
- import * as echarts from "echarts";
- export default {
- props: {
- height: {
- type: String,
- default: "100%",
- },
- width: {
- type: String,
- default: "100%",
- },
- options: {
- type: Object,
- default: null,
- },
- widthHtval: {
- type: [String, Boolean],
- default: false
- },
- clickOnTheEvent: { // 是否开启点击事件
- type: [Boolean],
- default: false
- }
- },
- components: {},
- data() {
- return {
- uuid: null,
- myChart: null,
- };
- },
- computed: {
- style() {
- return {
- height: this.height,
- width: this.width,
- };
- },
- },
- watch: {
- options() {
- if (this.myChart) {
- if (this.widthHtval) {
- this.myChart.resize({
- width: this.widthHtval
- })
- }
- this.myChart.setOption(this.options, { notMerge: true });
- }
- },
- },
- created() {
- this.uuid = this.idGen();
- console.log(this.uuid, '<===== uuId')
- },
- mounted() {
- this.myChart = echarts.init(document.getElementById(this.uuid));
- this.myChart.setOption(this.options);
- if (this.clickOnTheEvent) {
- this.myChart.getZr().on('click', params => {
- this.$emit('chartClickEvents', { params, myChart: this.myChart })
- })
- }
- },
- methods: {
- // idGen() {
- // return new Date().getTime();
- // },
- idGen() {
- const arr = new Uint8Array(16);
- window.crypto.getRandomValues(arr);
- arr[6] = (arr[6] & 0x0f) | 0x40; // 设置版本为 0100
- arr[8] = (arr[8] & 0x3f) | 0x80; // 设置变体为 10xx
- return [...arr].map((b) => ('00' + b.toString(16)).slice(-2)).join('').match(/.{1,8}/g).join('-');
- },
- },
- beforeDestroy() {
- if (this.myChart) {
- this.myChart.dispose();
- }
- }
- };
- </script>
- <style scoped lang="scss"></style>
|