1. Installationnpm install echarts --save 2. Use Echarts in vue2In the main.js file// Import echarts import echarts from 'echarts' Vue.prototype.$echarts = echarts Given a container<div id="myChart" :style="{width: '300px', height: '300px'}"></div>
//Introduce basic template let echarts = require('echarts/lib/echarts') //Introduce the bar chart component require('echarts/lib/chart/bar') //Introduce tooltip and title components require('echarts/lib/component/tooltip') require('echarts/lib/component/title') export default { name: 'hello', data() { return { msg: 'Welcome to Your Vue.js App' } }, mounted() { this.drawLine(); }, methods: { drawLine() { // Based on the prepared DOM, initialize the echarts instance let myChart = echarts.init(document.getElementById('myChart')) // Draw chart title: { text: 'Line chart stacking' }, tooltip: { trigger: 'axis' }, legend: { data: ['email marketing', 'affiliate advertising', 'video advertising', 'direct access', 'search engine'] }, grid: { left: '3%', right: '4%', bottom: '3%', containLabel: true }, toolbox: feature: saveAsImage: {} } }, xAxis: type: 'category', boundaryGap: false, data: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] }, yAxis: { type: 'value' }, series: [ { name: 'Email Marketing', type: 'line', stack: 'total amount', data: [120, 132, 101, 134, 90, 230, 210] }, { name: 'Alliance Advertising', type: 'line', stack: 'total amount', data: [220, 182, 191, 234, 290, 330, 310] }, { name: 'Video Ad', type: 'line', stack: 'total amount', data: [150, 232, 201, 154, 190, 330, 410] }, { name: 'Direct access', type: 'line', stack: 'total amount', data: [320, 332, 301, 334, 390, 330, 320] }, { name: 'Search Engine', type: 'line', stack: 'total amount', data: [820, 932, 901, 934, 1290, 1330, 1320] } ] } } } 3. Use Echarts in vue3 Because there is no Introduce echart in the root component, usually App.vueimport * as echarts from 'echarts' import { provide } from 'vue' export default { name: 'App', setup(){ provide('echarts',echarts) //provide }, components: } } It should be noted here that export { EChartsFullOption as EChartsOption, connect, disConnect, dispose, getInstanceByDom, getInstanceById, getMap, init, registerLocale, registerMap, registerTheme }; Define div on the page where you need to use it<div id="home-page-traffic_chart" style="width: 600px; height: 280px"> Then inject it on the page where you need to use Echartsexport default { name: 'data_page', setup () { const trafficData = ref({}) const echarts = inject('echarts') onMounted(() => { const myChart = echarts.init(document.getElementById('home-page-traffic_chart')) // Draw the chart myChart.setOption({ title: text: 'Today's call statistics' }, tooltip: { trigger: 'axis', axisPointer: type: 'shadow' } }, grid: { left: '3%', right: '4%', bottom: '3%', containLabel: true }, xAxis: [ { type: 'category', data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'], axisTick: { alignWithLabel: true } } ], yAxis: [ { type: 'value' } ], series: [ { name: 'Direct access', type: 'bar', barWidth: '60%', data: [10, 52, 200, 334, 390, 330, 220] } ] }) window.onresize = function () { myChart.resize() } }) return { } } } Effect picture: You may also be interested in:
|
<<: MySQL subqueries and grouped queries
>>: A brief discussion on two current limiting methods in Nginx
1. Preparation 1.1 Download the tomcat compressed...
Let’s take a look at the renderings first: XML/HT...
1. Remove backslashes through the "stripslas...
Table of contents 1. Declare a function 2. Callin...
This article uses an example to illustrate the us...
What is HTTP Compression Sometimes, relatively la...
This article shares the specific code for impleme...
Large Text Data Types in Oracle Clob long text ty...
Checkboxes are very common on web pages. Whether ...
Everyone is familiar with the meta tag in desktop...
Use javascript to implement a fixed sidebar, for ...
To put it simply, website construction is about &q...
Technical Background This application uses the vu...
In development projects, we can monitor SQL with ...
Looking at a website is actually like evaluating a...