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

代碼:
<template>
<div class="OverYearsPompany">
<div id="OverYearsPompanyChart" style="flex: 1; height: 368px; margin-top: -42px"></div>
</div>
</template>
<script>
import { getProposedInvestments } from '@/api/government';
const colors = [
['rgba(240, 7, 100, 1)', 'rgba(0, 215, 229, 1)'],
['rgba(240, 7, 100, 1)', 'rgba(0, 215, 229, 1)'],
['rgba(240, 7, 100, 1)', 'rgba(0, 215, 229, 1)'],
['rgba(240, 7, 100, 1)', 'rgba(0, 215, 229, 1)'],
];
export default {
data() {
return {
investmentsWayData: [],
investmentsWayDataCount: [],
investmentsWayDataCounts: [],
};
},
mounted() {
this.getProposedInvestments();
},
methods: {
initMap() {
var myChart = this.$echarts.init(document.getElementById('OverYearsPompanyChart'));
const option = {
tooltip: {
show: true,
trigger: 'axis',
axisPointer: {
type: 'shadow',
},
},
xAxis: {
type: 'value',
axisLabel: {
show: true,
color: '#02CFFCFF',
fontFamily: 'TencentSans',
},
axisLine: {
show: true,
lineStyle: {
color: '#02CFFCFF',
},
},
splitLine: {
show: true,
lineStyle: {
color: 'rgba(71, 126, 171, 1)',
},
},
},
yAxis: [
{
type: 'category',
inverse: true, //倒敘
axisLabel: {
color: '#02CFFCFF',
fontFamily: 'TencentSans',
},
axisTick: {
show: false,
},
axisLine: {
show: true,
lineStyle: {
color: '#02CFFCFF',
},
},
splitLine: {
show: true,
lineStyle: {
type: 'dotted',
color: 'rgba(71, 126, 171, 1)',
},
},
data: this.investmentsWayData,
},
],
series: [
{
type: 'bar',
barWidth: 15,
label: {
position: ['98%', -20],
show: true,
color: '#fff',
fontFamily: 'TencentSans',
},
data: this.investmentsWayDataCount,
itemStyle: {
color(params) {
const { dataIndex } = params;
let color = {
type: 'linear',
x: 1,
y: 0,
x2: 0,
y2: 0,
colorStops: [
{
offset: 0,
color: colors[dataIndex] ? colors[dataIndex][0] : 'red',
},
{
offset: 1,
color: colors[dataIndex] ? colors[dataIndex][1] : 'red',
},
],
};
return color;
},
},
},
],
};
myChart.setOption(option);
},
getProposedInvestments() {
getProposedInvestments().then((res) => {
const { status, data } = res;
const { proposedInvestmentsWayDis } = JSON.parse(data);
if (status === 200) {
// this.investmentsWayData=[{0: "合資", 1: "合作", 2: "獨資", 3: "其他"}]
this.investmentsWayData = proposedInvestmentsWayDis.map((item) => {
return item.wayDis;
});
// this.investmentsWayDataCount=[{0: "496", 1: "372", 2: "248", 3: "124"}]
this.investmentsWayDataCount = proposedInvestmentsWayDis.map((item) => {
return item.count;
});
// this.investmentsWayDataCounts=[{itemStyle:
// color:{
// 0: "rgba(240, 7, 100, 1)"
// 1: "rgba(0, 215, 229, 1)"}
// value: "496"}]
this.investmentsWayDataCounts = proposedInvestmentsWayDis.map((item, index) => {
return {
value: item.count,
itemStyle: {
color: colors[index],
},
};
});
this.initMap();
}
});
},
},
};
</script>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
vue刷新子組件、重置組件以及重新加載子組件項目實戰(zhàn)記錄
在vue開發(fā)中出于各種目的,我們常常需要讓組件重新加載渲染,這篇文章主要給大家介紹了關(guān)于vue刷新子組件、重置組件以及重新加載子組件的相關(guān)資料,需要的朋友可以參考下2023-12-12
Vue+Openlayer實現(xiàn)圖形的拖動和旋轉(zhuǎn)變形效果
Openlayer具有自己的擴展插件ol-ext,可以用來實現(xiàn)圖形的拖拽、旋轉(zhuǎn)、縮放、拉伸、移動等操作,本文將主要介紹通過Openlayer實現(xiàn)圖形的拖動和旋轉(zhuǎn),需要的同學(xué)可以學(xué)習(xí)一下2021-11-11
vuecli項目構(gòu)建SSR服務(wù)端渲染的實現(xiàn)
這篇文章主要介紹了vuecli項目構(gòu)建SSR服務(wù)端渲染的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-10-10
詳解Vue3.0 + TypeScript + Vite初體驗
這篇文章主要介紹了詳解Vue3.0 + TypeScript + Vite初體驗,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-02-02

