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
I searched for three-level linkage on the Interne...
1. Official Introduction grep is a commonly used ...
What is a primary key? A primary key is a column ...
Problem Description In the recent background serv...
The isnull() function cannot be used as a substit...
You can install Docker and perform simple operati...
This article example shares the specific code of ...
Table of contents What is the Observer Pattern? S...
background When we want to log in to the MySQL da...
Table of contents Methods of String Object Method...
This article shares the specific code for JavaScr...
Carousel The main idea is: In the large container...
We are not discussing PHP, JSP or .NET environmen...
Table of contents 1. Introduction II. Monitoring ...
CentOS8 was released a few days ago. Although it ...