123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- <template>
- <div id="qwe" style="width: 100%; height: 100%; "></div>
- </template>
- <script>
- import { oldPersonSelectByJob } from '../../api'
- import 'echarts-liquidfill'
- export default {
- name: "PatrolmanJobDistributionCount",
- data() {
- return {
- dataArr: [],
- colorArr: [
- { color1: '#00D7FF', color2: '#00D7FF' },
- { color1: '#E9F82D', color2: '#E9F82D' },
- { color1: '#32FC6B', color2: '#32FC6B' },
- { color1: '#FEC400', color2: '#FEC400' }
- ]
- }
- },
- methods: {
- async draw() {
- const result = await oldPersonSelectByJob({}, 'POST');
- this.dataArr = result;
- const seriesArr = [];
- const titleArr = [];
- for(let i = 0; i < this.dataArr.length; i++) {
- const d = this.dataArr[i];
- seriesArr.push({
- type: 'liquidFill',
- data: [`${(parseInt(d.value) / 100).toFixed(2)}`],
- radius: '40%',
- center: [`${ 12.5 + i * 25 }%`, `40%`],
- backgroundStyle: {
- borderColor: this.colorArr[i].color1,
- color: "#011065"
- },
- outline: {
- show: false
- },
- waveAnimation: false, // 禁止左右波动
- label: {
- normal: {
- position: ['50%', '50%'],
- textStyle: {
- fontSize: this.fontSize(0.2),
- color: this.colorArr[i].color1
- },
- formatter: `${ d.value }`
- }
- },
- itemStyle: {
- normal: {
- color: new this.$echarts.graphic.LinearGradient(
- 0, 0, 0, 1,
- [
- {offset: 0, color: this.colorArr[i].color1},
- {offset: 1, color: this.colorArr[i].color2}
- ]
- )
- }
- }
- });
- titleArr.push({
- text: d.label,
- left: `${ 12.5 + i * 25 }%`,
- top: `70%`,
- textAlign: "center",
- textStyle: {
- fontSize: this.fontSize(0.18),
- fontWeight: 'normal',
- color: '#fff'
- }
- });
- }
- let myChart = this.$echarts.init(document.getElementById('qwe'));
- myChart.setOption({
- title: titleArr,
- xAxis: {
- type: 'value',
- max: 100,
- splitLine: {
- show: false
- },
- axisLine: {
- show: false
- },
- axisLabel: {
- show: false
- },
- axisTick: {
- show: false
- }
- },
- yAxis: {
- type: 'category',
- splitLine: {
- show: false
- },
- axisLine: {
- show: false
- },
- axisLabel: {
- show: false
- },
- axisTick: {
- show: false
- }
- },
- series: seriesArr
- });
- },
- fontSize(res) {
- let clientWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
- if (!clientWidth) return;
- let fontSize = 100 * (clientWidth / 1920);
- return res * fontSize;
- }
- },
- watch: {
- data() {
- this.myChart.destroy();
- this.draw();
- }
- },
- mounted() {
- this.draw();
- }
- }
- </script>
- <style scoped>
- </style>
|