在vue中 echarts 柱狀圖調(diào)后臺接口

1.安裝echarts依賴
npm install echarts -S 或cnpm install echarts -S

2.全局引用
// main.js引入echarts
import echarts from 'echarts' //有時語法報錯 或使用 import * as echarts from 'echarts'
Vue.prototype.$echarts = echarts

3.創(chuàng)建組件
<template>
<div id="echarts">
<div >
<div>
<div id="myChart" :style="{ width: '600px', height: '300px' }"></div>
</div>
</div>
</div>
</template>
<script>
import * as echarts from 'echarts'
import { getarrival } from '@/api/product' //調(diào)用后臺接口
export default {
name: 'Echarts',
data() {
return {
dataList: [],
obj:{
id:1
}
}
},
mounted() {
this.drawLine()
},
methods: {
drawLine() {
getarrival(this.obj).then((res) => {
this.dataList = res.data.data.arrivel_later_result.bar //接口返回數(shù)據(jù)賦值this.dataList
// 基于準(zhǔn)備好的dom,初始化echarts實(shí)例
let myChart = echarts.init(document.getElementById('myChart'))
// 繪制圖表
myChart.setOption({
title: {
text: this.dataList.title.text,
subtext: this.dataList.title.subtext,
left: this.dataList.title.left
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow'
}
},
xAxis: {
type: 'category',
data: this.dataList.xAxis.data
},
yAxis: {
type: 'value'
// boundaryGap: [0, 0.01]
},
series: [
{
name: '遲到占比',
type: 'bar',
barWidth: 30, //柱圖寬度
data: this.dataList.series[0].data
}
]
})
})
},

}
}
</script>
<style scoped>
</style>
4.效果實(shí)現(xiàn)

image.png

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容