This article shares the specific code of vue echarts to realize the horizontal bar chart for your reference. The specific content is as follows Result: Code: <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, // inverse 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: "Joint venture", 1: "Cooperation", 2: "Sole proprietorship", 3: "Other"}] 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> The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: How to set the user root password and remote connection method for Alibaba Cloud ECS instance
1. Demand The local test domain name is the same ...
background Use idea with docker to realize the wh...
background This article mainly tests whether the ...
Table of contents A pitfall about fileReader File...
1. Download the CentOS image 1.1 Download website...
1. Case Take all employees who are not the head o...
Three MySQL instance processes are started on one...
Preface When using the MySQL database, sometimes ...
1. CSS Miscellaneous Icons There are three ways t...
Table of contents status quo Solution Further sol...
SVG has been widely used in recent years due to i...
one. Preface <br />You will see this kind of...
Table of contents 1. Easy to read code 1. Unified...
1. Check the character set of the database The ch...
This article shares the specific code of JavaScri...