123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- <template>
- <div id="myChartindex1" style="width: 100%; height: 100%;"></div>
- </template>
- <script>
- import {oldPersonOldType} from '../../api'
- //圆角柱状图
- import echarts from 'echarts'
- export default {
- data() {
- return {
- dataArr: [],
- colorArr: [
- {color1: '#9db9ff', color2: '#00f'},
- {color1: '#ffe49e', color2: '#ffb300'}
- ],
- myChart: null
- }
- },
- methods: {
- async draw() {
- if (this.myChart != '' && this.myChart != null) {
- this.myChart.clear();
- }
- console.log("kokokokokokoko");
- const result = await oldPersonOldType({}, 'POST');
- this.dataArr = result;
- this.myChart = this.$echarts.init(document.getElementById('myChartindex1'));
- this.myChart.setOption({
- grid: {
- left: '0%',
- right: '0%',
- top: '22%',
- bottom: '20%'
- },
- xAxis: {
- type: 'category',
- data: this.dataArr.map((item) => item.label),
- axisTick: {
- show: false
- },
- axisLabel: {
- interval:0,
- margin:16,
- show: true,
- textStyle: {
- color: 'white',
- fontSize: this.fontSize(0.14)
- },
- },
- },
- yAxis: {
- type: 'value',
- axisLabel: {
- show: false
- },
- splitLine: {
- show: true,
- lineStyle: {
- color: ['#315070'],
- width: 1,
- type: 'solid'
- }
- },
- axisLine: {
- show: false
- },
- axisTick: {
- show: false
- },
- },
- series: [
- {
- data: this.dataArr.map((item) => item.value),
- type: 'bar',
- barWidth: 14,
- itemStyle: {
- emphasis: {
- barBorderRadius: 7
- },
- normal: {
- barBorderRadius: 7,
- color: (params) => {
- return new echarts.graphic.LinearGradient(
- 0, 0, 0, 1,
- [
- {
- offset: 0,
- color: this.colorArr[params.dataIndex % 2 == 0 ? 0 : 1].color1
- },
- {
- offset: 1,
- color: this.colorArr[params.dataIndex % 2 == 0 ? 0 : 1].color2
- }
- ]
- )
- }
- }
- },
- label: {
- show: true,
- position: 'top',
- formatter: '{c}人',
- offset: [0, -10],
- color: '#fff',
- textStyle: {
- color: 'white',
- fontSize: this.fontSize(0.13)
- },
- },
- z: 1
- },
- {
- type: 'line',
- data: this.dataArr.map((item) => item.value),
- symbol: (params, item) => {
- return item.dataIndex % 2 == 0 ? `image://${require("../../assets/index/q1.png")}` : `image://${require("../../assets/index/q2.png")}`;
- },
- symbolSize: [19, 19],
- lineStyle: {
- color: 'rgba(255, 165, 0, 1)',
- width: 1,
- type: 'dashed'
- },
- z: 2
- }
- ]
- });
- },
- fontSize(res) {
- let clientWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
- if (!clientWidth) return;
- let fontSize = 100 * (clientWidth / 1920);
- return res * fontSize;
- }
- },
- mounted() {
- // this.draw();
- }
- }
- </script>
- <style type="text/css">
- </style>
|