在vue中使用vue-echarts-v3的實(shí)例代碼
特征
•輕量,高效,按需綁定事件
•支持按需導(dǎo)入ECharts.js圖表和組件
•支持組件調(diào)整大小事件自動(dòng)更新視圖
一、安裝
npm install --save echarts vue-echarts-v3
二、用法
用 vue-cli 搭建的項(xiàng)目,打開 build 文件夾中的 webpack.base.conf.js 文件
1、webpack 1.x 修改成如下
{
test: /\.js$/,
loader: 'babel',
include: [
path.join(prjRoot, 'src'),
path.join(prjRoot, 'node_modules/vue-echarts-v3/src')
],
exclude: /node_modules(?![\\/]vue-echarts-v3[\\/]src[\\/])/
},
2、webpack 2.x 修改成如下
{
test: /\.js$/,
loader: 'babel-loader',
include: [resolve('src'), resolve('test'), resolve('node_modules/vue-echarts-v3/src')]
}
3、導(dǎo)入所有圖表和組件
import IEcharts from 'vue-echarts-v3/src/full.js';
4、手動(dòng)導(dǎo)入ECharts.js模塊以減少捆綁包大小
import IEcharts from 'vue-echarts-v3/src/lite.js'; import 'echarts/lib/component/title'; //引入標(biāo)題組件 import 'echarts/lib/component/legend'; //引入圖例組件 import 'echarts/lib/component/tooltip'; //引入提示框組件 import 'echarts/lib/component/toolbox'; //引入工具箱組件 // ...(引入自己需要的) import 'echarts/lib/chart/pie'; //以餅圖為例
三、例子
關(guān)于Echarts的API使用參照 Echarts官網(wǎng)
•從接口獲取的動(dòng)態(tài)數(shù)據(jù)可以直接通過props從父組件傳過來,替換下面的series[0].data數(shù)組中的數(shù)據(jù)
•也可以從這個(gè)組件中從接口獲取動(dòng)態(tài)數(shù)據(jù)。但option屬性對(duì)應(yīng)的變量pie必須寫在computed中return出來,不能再寫在data中,否則獲取不到數(shù)據(jù)
<template>
<div class="echarts">
<IEcharts :option="pie" @ready="onReady" @click="onClick"></IEcharts>
</div>
</template>
<script>
import IEcharts from 'vue-echarts-v3/src/lite.js';
import 'echarts/lib/component/title'; //引入標(biāo)題組件
import 'echarts/lib/component/legend'; //引入圖例組件
import 'echarts/lib/chart/pie';
export default {
components: {IEcharts},
data: () => ({
pie: {
title: {
text: 'ECharts Demo'
},
tooltip: {},
legend:{
type: 'plain',
orient: 'vertical',
right: 10,
top: 20,
},
series: [{
type: 'pie',
data: [
{name: 'A', value: 1211},
{name: 'B', value: 2323},
{name: 'C', value: 1919}
]
}]
}
}),
methods: {
onReady(instance) {
console.log(instance);
},
onClick(event, instance, echarts) {
console.log(arguments);
}
}
};
</script>
<style scoped>
.echarts{
width: 400px;
height: 400px;
margin: auto;
text-align: center;
}
</style>
總結(jié)
以上所述是小編給大家介紹的在vue中使用vue-echarts-v3的實(shí)例代碼,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
基于Vue3實(shí)現(xiàn)SSR(服務(wù)端渲染)功能
在現(xiàn)代網(wǎng)頁開發(fā)中,用戶體驗(yàn)日益成為網(wǎng)站成功的重要因素,從加載時(shí)間到SEO優(yōu)化,越來越多的開發(fā)者開始關(guān)注使用服務(wù)端渲染(SSR)來提升應(yīng)用的表現(xiàn),本文將深入探討 Vue 3 的 SSR 特性,并以示例代碼展示如何實(shí)現(xiàn)這一功能,需要的朋友可以參考下2024-11-11
使用vue-router為每個(gè)路由配置各自的title
這篇文章主要介紹了如何使用vue-router為每個(gè)路由配置各自的title,及使用vue router的方法,需要的朋友可以參考下2018-07-07
vue-echarts如何實(shí)現(xiàn)圖表組件封裝詳解
由于在項(xiàng)目中需要對(duì)數(shù)據(jù)進(jìn)行可視化處理,也就是用圖表展示,所以下面這篇文章主要給大家介紹了關(guān)于vue-echarts如何實(shí)現(xiàn)圖表組件封裝的相關(guān)資料,需要的朋友可以參考下2022-05-05
vue+express 構(gòu)建后臺(tái)管理系統(tǒng)的示例代碼
這篇文章主要介紹了vue+express 構(gòu)建后臺(tái)管理系統(tǒng)的示例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-07-07
VUE3封裝一個(gè)Hook的實(shí)現(xiàn)示例
本文主要介紹了VUE3封裝一個(gè)Hook的實(shí)現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2025-01-01

