vue echarts實(shí)現(xiàn)橫向柱狀圖
本文實(shí)例為大家分享了vue echarts實(shí)現(xiàn)橫向柱狀圖的具體代碼,供大家參考,具體內(nèi)容如下
實(shí)現(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: "獨(dú)資", 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)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 解決echarts 一條柱狀圖顯示兩個(gè)值,類似進(jìn)度條的問題
- Echarts基本入門之柱狀圖、折線圖通用配置
- Echarts Bar橫向柱狀圖實(shí)例代碼
- Vue使用Echarts實(shí)現(xiàn)立體柱狀圖
- vue echarts實(shí)現(xiàn)柱狀圖動(dòng)態(tài)展示
- uniapp引用echarts的詳細(xì)步驟(附柱狀圖實(shí)例)
- echarts動(dòng)態(tài)渲染柱狀圖背景顏色及頂部數(shù)值方法詳解
- 基于vue+echarts實(shí)現(xiàn)柱狀圖漸變色效果(每個(gè)柱子顏色不同)
- Echarts柱狀圖修改柱子顏色漸變及柱子圓角效果實(shí)例
相關(guān)文章
vue如何將后臺(tái)返回的數(shù)字轉(zhuǎn)換成對(duì)應(yīng)的文字
這篇文章主要介紹了vue如何將后臺(tái)返回的數(shù)字轉(zhuǎn)換成對(duì)應(yīng)的文字,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-10-10vue中Vue.set()的使用以及對(duì)其進(jìn)行深入解析
vue不允許在已經(jīng)創(chuàng)建的實(shí)例上動(dòng)態(tài)添加新的根級(jí)響應(yīng)式屬性,不過可以使用Vue.set()方法將響應(yīng)式屬性添加到嵌套的對(duì)象上,下面這篇文章主要給大家介紹了關(guān)于vue中Vue.set()的使用以及對(duì)其進(jìn)行深入解析的相關(guān)資料,需要的朋友可以參考下2023-01-01Vue-drag-resize 拖拽縮放插件的使用(簡單示例)
本文通過代碼給大家介紹了Vue-drag-resize 拖拽縮放插件使用簡單示例,代碼簡單易懂,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-12-12vue-cli 腳手架基于Nightwatch的端到端測試環(huán)境的過程
這篇文章主要介紹了vue-cli 腳手架基于Nightwatch的端到端測試環(huán)境的過程,需要的朋友可以參考下2018-09-09vue3.0+element表格獲取每行數(shù)據(jù)代碼示例
這篇文章主要給大家介紹了關(guān)于vue3.0+element表格獲取每行數(shù)據(jù)的相關(guān)資料,在element-ui中,你可以通過為表格的行綁定單擊事件來獲取表格中的一行數(shù)據(jù),需要的朋友可以參考下2023-09-09Vue項(xiàng)目中實(shí)現(xiàn)AES加密解密的全過程
AES算法是一種對(duì)稱加密算法,用于加密和解密數(shù)據(jù),下面這篇文章主要給大家介紹了關(guān)于Vue項(xiàng)目中實(shí)現(xiàn)AES加密解密的相關(guān)資料,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下2024-08-08關(guān)于Vue的 watch、computed和methods的區(qū)別匯總
這篇文章主要介紹關(guān)于Vue的 watch、computed和methods的區(qū)別,下面文章將圍繞Vue的 watch、computed和methods的續(xù)航管資料展開全文它們之間區(qū)別的內(nèi)容,需要的朋友可以參考一下,希望能幫助到大家2021-11-11更強(qiáng)大的vue ssr實(shí)現(xiàn)預(yù)取數(shù)據(jù)的方式
這篇文章主要介紹了更強(qiáng)大的 vue ssr 預(yù)取數(shù)據(jù)的方式,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-07-07