官網 https://echarts.apache.org/zh/index.html
安裝配置
npm install echarts --save
main.js
import ECharts from 'echarts'
Vue.prototype.$echarts =
使用
<divstyle="height: 300px;width:" ref="myChart" ></div>
mounted() {
// 1.配置圖表的資料和參數
let option = {
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'
}]
}
// 2.建立圖表
let chart = this.$echarts.init(this.$refs.myChart)
// 3,導入圖表的配置
chart.setOption(option)
// 4添加視窗大小改變監聽事件,當視窗大小改變時,圖表會重新繪制,自适應視窗大小
window.addEventListener('resize', function () {
chart.resize()
})
}
折線圖
option = {
title: {
text: '折線圖堆疊'
},
tooltip: {
trigger: 'axis'
},
legend: {
data: ['郵件營銷', '聯盟廣告', '視訊廣告', '直接通路', '搜尋引擎']
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
toolbox: {
feature: {
saveAsImage: {}
}
},
xAxis: {
type: 'category',
boundaryGap: false,
data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
},
yAxis: {
type: 'value'
},
series: [
{
name: '郵件營銷',
type: 'line',
stack: '總量',
data: [120, 132, 101, 134, 90, 230, 210]
},
{
name: '聯盟廣告',
type: 'line',
stack: '總量',
data: [220, 182, 191, 234, 290, 330, 310]
},
{
name: '視訊廣告',
type: 'line',
stack: '總量',
data: [150, 232, 201, 154, 190, 330, 410]
},
{
name: '直接通路',
type: 'line',
stack: '總量',
data: [320, 332, 301, 334, 390, 330, 320]
},
{
name: '搜尋引擎',
type: 'line',
stack: '總量',
data: [820, 932, 901, 934, 1290, 1330, 1320]
}
]
};
柱狀圖
{
xAxis: {
type: 'category',
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
},
yAxis: {
type: 'value'
},
series: [{
data: [120, 200, 150, 80, 70, 110, 130],
type: 'bar'
}]
}
餅狀圖
{
title: {
text: '某站點使用者通路來源',
subtext: '純屬虛構',
left: 'center'
},
tooltip: {
trigger: 'item',
formatter: '{a} <br/>{b} : {c} ({d}%)'
},
legend: {
orient: 'vertical',
left: 'left',
data: ['直接通路', '郵件營銷', '聯盟廣告', '視訊廣告', '搜尋引擎']
},
series: [
{
name: '通路來源',
type: 'pie',
radius: '55%',
center: ['50%', '60%'],
data: [
{value: 335, name: '直接通路'},
{value: 310, name: '郵件營銷'},
{value: 234, name: '聯盟廣告'},
{value: 135, name: '視訊廣告'},
{value: 1548, name: '搜尋引擎'}
],
emphasis: {
itemStyle: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)'
}
}
}
]
}