1. Install and importnpm install echarts --save //main.js // import echarts from 'echarts'; import * as echarts from 'echarts'; // If you install echarts 5 or above, you need to import it in this way Vue.prototype.$echarts = echarts 2. Define the anti-shake function Portal: Implementing anti-shake, throttling and application scenarios of functions in Vue // utils/common.js // Anti-shake function _debounce(fn, delay = 300) { var timer = null; return function () { var _this = this; var args = arguments; if (timer) clearTimeout(timer); timer = setTimeout(function () { fn.apply(_this, args); }, delay); }; } export{ _debounce, } 3. Draw chart code<template> <div class="charts"> <div id="lineChart" :style="{ width: '100%', height: '400px' }"></div> </div> </template> <script> import { _debounce } from '@/utils/common.js' export default { data() { return {}; }, methods: { drawLine() { // Initialize the echarts instance based on the prepared dom let lineChart = this.$echarts.init(document.getElementById("lineChart")); lineChart.setOption({ title: text: "Rainfall and flow relationship diagram", x: "center", }, xAxis: type: "category", data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"], }, yAxis: { type: "value", }, series: [ { data: [820, 932, 901, 934, 1290, 1330, 1320], type: "line", }, ], }); }, resizeCharts:_debounce(function(){ this.$echarts.init(document.getElementById('lineChart')).resize() },500) }, mounted() { this.drawLine(); window.addEventListener('resize',this.resizeCharts); }, beforeDestroy () { window.addEventListener('resize',this.resizeCharts); }, }; </script> init Method Create an ECharts instance and return echartsInstance. You cannot initialize multiple ECharts instances on a single container. (dom: HTMLDivElement|HTMLCanvasElement, theme?: Object|string, opts?: { devicePixelRatio?: number, renderer?: string, useDirtyRect?: boolean, // Supported since `v5.0.0` width?: number|string, height?: number|string, locale?: string }) => ECharts dom: instance container, usually a div element with height and width. Note: If the div is hidden, ECharts may not be able to obtain the height and width of the div, resulting in initialization failure. In this case, you can explicitly specify the style.width and style.height of the div, or manually call echartsInstance.resize to adjust the size after the div is displayed. ECharts 3 supports using canvas elements directly as containers, so that after drawing the chart, the canvas can be directly applied to other places as an image. For example, in WebGL as a texture, this can support real-time refresh of the chart compared to using echartsInstance.getDataURL to generate an image link. theme: The theme of the application. It can be a theme configuration object, or a theme name that has been registered through echarts.registerTheme. opts: additional parameters. There are several options:
If you do not specify a theme, you also need to pass null before passing opts, such as: const chart = echarts.init(dom, null, {renderer: 'svg'}); Resize method official website explanation Change the chart size. This function needs to be called manually when the container size changes. (opts?: { width?: number|string, height?: number|string, silent?: boolean, animation?: duration?: number easing?: string } }) => ECharts parameter: opts can be omitted. There are several options:
hint: This concludes this article about how to use Vue to implement Echarts chart width and height adaptation. For more information about Vue Echarts chart width and height adaptation, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Essential tools for web design: Firefox Web Developer plugin CSS tool set tutorial
>>: A brief analysis of how to use border and display attributes in CSS
Table of contents 1. Install ESXi 2. Set up ESXi ...
Before talking about CSS priority, we need to und...
HTML img tag: defines an image to be introduced in...
xml <?xml version="1.0" encoding=&qu...
Preface Sass is an extension of the CSS3 language...
The Docker publishing method provides many conven...
<br />Scientifically Design Your Website: 23...
This article shares with you the installation and...
Preface When my team was developing the tax syste...
A colleague once told me to use a temporary table...
WML (Wireless Markup Language). It is a markup la...
Table of contents 1. Custom routing 2. Tab naviga...
1. Download address: http://dev.mysql.com/downloa...
Apache Tomcat is an open source software that imp...
Table of contents Preface first step: Step 2: Mod...