vue實(shí)現(xiàn)橫向斜切柱狀圖
更新時間:2021年09月05日 10:30:35 作者:tendernessxy
這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)橫向斜切柱狀圖,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實(shí)例為大家分享了vue實(shí)現(xiàn)橫向斜切柱狀圖的具體代碼,供大家參考,具體內(nèi)容如下
實(shí)現(xiàn)效果:

實(shí)現(xiàn)代碼:
<template>
<div class="Consumption">
<div style="width: 350px; height: 180px" ref="ConsumptionChart" />
</div>
</template>
<script>
import echarts from 'echarts'
const myShape = {
x: 0,
y: 0,
width: 10 //間距
}
// 繪制左側(cè)面
const InclinedRoofBar = echarts.graphic.extendShape({
shape: myShape,
buildPath: function(ctx, shape) {
// 會canvas的應(yīng)該都能看得懂,shape是從custom傳入的
const xAxisPoint = shape.xAxisPoint
const c0 = [shape.x, shape.y]
const c1 = [shape.x + 14, shape.y - 10]
const c2 = [xAxisPoint[0], xAxisPoint[1] - 10]
const c3 = [xAxisPoint[0], xAxisPoint[1]]
ctx
.moveTo(c0[0], c0[1])
.lineTo(c1[0], c1[1])
.lineTo(c2[0], c2[1])
.lineTo(c3[0], c3[1])
.closePath()
}
})
const colors = ['rgba(50, 197, 255, 0.8)', 'rgba(0, 253, 255, 0.8)', 'rgba(255, 235, 0, 0.8)']
const colorss = ['rgba(0, 145, 255, 1)', 'rgba(68, 215, 182, 1)', 'rgba(215, 170, 68, 1)']
// 注冊三個面圖形
echarts.graphic.registerShape('InclinedRoofBar', InclinedRoofBar)
const defaultOption = {
tooltip: {
show: true,
trigger: 'axis',
axisPointer: {
type: 'shadow'
}
},
grid: {
top: 10,
bottom: 30,
left: 10,
right: 10,
containLabel: true
},
yAxis: {
type: 'category',
data: [],
axisLine: {
show: false
},
axisTick: {
show: false
},
axisLabel: {
color(value, index) {
return colorss[index]
},
fontSize: 14
}
},
xAxis: {
type: 'value',
axisLine: {
show: false
},
min: 0,
splitLine: {
show: false
},
axisTick: {
show: false
},
axisLabel: {
show: false
},
boundaryGap: ['20%', '20%']
},
series: [
{
type: 'custom',
name: '',
itemStyle: {
color: 'rgba(44, 197, 253, 1)'
},
renderItem: (params, api) => {
const location = api.coord([api.value(0), api.value(1)])
const xlocation = api.coord([0, api.value(1)])
return {
type: 'InclinedRoofBar',
shape: {
api,
xValue: api.value(0),
yValue: api.value(1),
x: location[0],
y: location[1] + myShape.width,
xAxisPoint: [xlocation[0], xlocation[1] + myShape.width]
},
style: {
fill: new echarts.graphic.LinearGradient(0, 0, 1, 0, [
{
offset: 0,
color: colors[params.dataIndex]
},
{
offset: 1,
color: colorss[params.dataIndex]
}
])
}
}
},
data: []
},
{
type: 'bar',
label: {
normal: {
show: true,
position: 'right',
fontSize: 14,
offset: [15, 0]
}
},
showBackground: false,
barWidth: 14,
backgroundStyle: {
color: 'rgba(50, 197, 255, 0.1)'
},
itemStyle: {
color: 'transparent'
},
tooltip: {
show: false
},
data: []
}
]
}
export default {
data() {
return {
myChart: null
}
},
mounted() {
this.myChart = echarts.init(this.$refs.ConsumptionChart)
},
methods: {
getOption(seriesData) {
const option = defaultOption
const { yAxis, series } = option
// 處理數(shù)據(jù)
yAxis.data = ['低', '中', '高']
series[0].data = seriesData
series[1].data = seriesData.map((item, index) => Object.assign(item, { label: { color: colorss[index] } }))
this.myChart.setOption(option)
}
}
}
</script>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- vue+Echart實(shí)現(xiàn)立體柱狀圖
- Vue使用Echart圖標(biāo)插件之柱狀圖
- 詳解vue使用Echarts畫柱狀圖
- Vue+Echart柱狀圖實(shí)現(xiàn)疫情數(shù)據(jù)統(tǒng)計(jì)
- vue echarts實(shí)現(xiàn)橫向柱狀圖
- vue+echart實(shí)現(xiàn)雙柱狀圖
- vue+echarts實(shí)現(xiàn)堆疊柱狀圖
- vue+echarts實(shí)現(xiàn)進(jìn)度條式柱狀圖
- Vue使用Echarts實(shí)現(xiàn)立體柱狀圖
- Vue+Antv?F2實(shí)現(xiàn)層疊柱狀圖
相關(guān)文章
vue2.x element-ui實(shí)現(xiàn)pc端購物車頁面demo
這篇文章主要為大家介紹了vue2.x element-ui實(shí)現(xiàn)pc端購物車頁面demo,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-06-06
詳解vue-router數(shù)據(jù)加載與緩存使用總結(jié)
這篇文章主要介紹了詳解vue-router數(shù)據(jù)加載與緩存使用總結(jié),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-10-10
Vue3 computed初始化獲取設(shè)置值實(shí)現(xiàn)示例
這篇文章主要為大家介紹了Vue3 computed初始化以及獲取值設(shè)置值實(shí)現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-10-10
用vue設(shè)計(jì)一個數(shù)據(jù)采集器
這篇文章主要介紹了如何用vue設(shè)計(jì)一個數(shù)據(jù)采集器,幫助大家更好的理解和學(xué)習(xí)使用vue框架,感興趣的朋友可以了解下2021-04-04

