Introduction to two ways to use Echarts in Vue

不言
Release: 2018-07-03 14:35:57
Original
1641 people have browsed it

This article mainly introduces two ways to use Echarts in Vue. This article introduces you to you in very detail and has certain reference value. Friends in need can refer to

1. Directly introduce echarts

First npm install echarts

npm install echarts --save
Copy after login

Development:

main.js

import myCharts from './comm/js/myCharts.js' Vue.use(myCharts) myCharts.js /** * 各种画echarts图表的方法都封装在这里 */ import echarts from 'echarts' (function() { var chart = {}; chart.install = function(vue) { vue.prototype.$chart = { //画一条简单的线 line1: function(id) { this.chart = echarts.init(document.getElementById(id)); this.chart.clear(); const optionData = { 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', smooth: true }] }; this.chart.setOption(optionData); }, } } if(typeof exports == 'object') { module.exports = chart } })() hello.vue ... 

... mounted() { this.$chart.line1('chart1'); },
Copy after login

2. Use vue-echarts

First npm install vue-echarts

npm install vue-echarts
Copy after login

Development:

main.js

import ECharts from 'vue-echarts/components/ECharts' import 'echarts/lib/chart/bar' import 'echarts/lib/component/tooltip' Vue.component('chart', ECharts) hello.vue ...  ... data: function() { return { orgOptions: {}, } }, ... mounted() { this.orgOptions = { 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', smooth: true }] } }
Copy after login

The above is the entire content of this article, I hope it will be helpful to everyone Learning will be helpful. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

Introduction to several import methods commonly used in VUE (modules, files)

Vue How to set login permissions for routing

#

The above is the detailed content of Introduction to two ways to use Echarts in Vue. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn