| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256 |
- <template>
- <div class="chart-wrap">
- <v-chart autoresize :option="option"/>
- </div>
- </template>
- <script>
- import * as echarts from 'echarts'
- export default {
- name: 'Dlydtssx',
- data() {
- return {
- option: {}
- }
- },
- created() {
- this.getOption()
- },
- methods: {
- getOption() {
- const data = [{
- name: '第一季度',
- value: 40
- }, {
- name: '第二季度',
- value: 30
- }, {
- name: '第三季度',
- value: 20
- }, {
- name: '第四季度',
- value: 10
- }]
- const name = data.map((item) => item.name)
- const value = data.map((item) => item.value)
- const sum = value.reduce((a, b) => {
- return a + b
- })
- const colors = [
- [
- new echarts.graphic.LinearGradient(0, 1, 0, 0, [{offset: 0, color: 'rgb(82, 113, 195)'}, {
- offset: 1,
- color: 'rgb(120, 142, 237)'
- }], false),
- new echarts.graphic.LinearGradient(0, 1, 0, 0, [{offset: 0, color: 'rgb(81, 129, 192)'}, {
- offset: 1,
- color: 'rgb(123, 148, 234)'
- }], false),
- new echarts.graphic.LinearGradient(0, 1, 0, 0, [{offset: 0, color: 'rgb(89, 137, 188)'}, {
- offset: 1,
- color: 'rgb(113, 173, 229)'
- }], false),
- new echarts.graphic.LinearGradient(0, 1, 0, 0, [{offset: 0, color: 'rgb(88, 166, 191)'}, {
- offset: 1,
- color: 'rgb(128, 230, 226)'
- }], false)
- ],
- ['rgb(41, 73, 110)',
- 'rgb(41, 73, 110)',
- 'rgb(41, 73, 110)',
- 'rgb(41, 73, 110)'
- ]
- ]
- const series = []
- const yAxis = []
- for (let i = 0; i < data.length; i++) {
- series.push({
- name: '',
- type: 'pie',
- clockWise: false, // 顺时加载
- hoverAnimation: false, // 鼠标移入变大
- radius: [90 - i * 15 + '%', 84 - i * 15 + '%'],
- center: ['45%', '50%'],
- label: {
- show: false
- },
- itemStyle: {
- label: {
- show: false
- },
- labelLine: {
- show: false
- },
- borderRadius: 60 // 设置每一段子项目的圆角
- },
- data: [{
- value: data[i].value,
- name: data[i].name
- },
- {
- value: sum - data[i].value,
- name: '',
- itemStyle: {
- color: 'transparent',
- borderRadius: 60 // 设置每一段子项目的圆角
- },
- tooltip: {
- show: false
- },
- hoverAnimation: false
- }
- ]
- })
- series.push({
- name: '',
- type: 'pie',
- silent: true,
- z: 1,
- clockWise: false, // 顺时加载
- hoverAnimation: false, // 鼠标移入变大
- radius: [90 - i * 15 + '%', 84 - i * 15 + '%'],
- center: ['45%', '50%'],
- label: {
- show: false
- },
- itemStyle: {
- label: {
- show: false
- },
- labelLine: {
- show: false
- },
- borderRadius: 60 // 设置每一段子项目的圆角
- },
- data: [{
- value: 7.5,
- itemStyle: {
- color: colors[1][i]
- },
- tooltip: {
- show: false
- },
- hoverAnimation: false
- },
- {
- value: 2.5,
- itemStyle: {
- color: 'rgba(0,0,0,0)',
- borderWidth: 0,
- borderRadius: 60 // 设置每一段子项目的圆角
- },
- tooltip: {
- show: false
- },
- hoverAnimation: false
- }
- ]
- })
- yAxis.push(((data[i].value / sum) * 100).toFixed(0) + '%')
- }
- this.option = {
- color: colors[0],
- legend: {
- show: true,
- icon: 'circle',
- top: '2%',
- left: '60%',
- width: '100%',
- height: '100%',
- data: name,
- orient: 'vertical',
- formatter: (name) => {
- return (
- '{title|' + name + '} {value|' + data.find((item) => {
- return item.name === name
- }).value + '}'
- )
- },
- textStyle: {
- rich: {
- title: {
- fontSize: 14,
- lineHeight: 30,
- color: '#ffffff'
- },
- value: {
- fontSize: 14,
- lineHeight: 30,
- color: '#fff'
- }
- }
- }
- },
- tooltip: {
- show: true,
- trigger: 'item',
- formatter: '{a}<br>{b}:{c}({d}%)'
- },
- grid: {
- top: '3%',
- left: '40%',
- width: '40%',
- height: '30%',
- containLabel: true
- },
- yAxis: [{
- type: 'category',
- inverse: true,
- axisLine: {
- show: false
- },
- axisTick: {
- show: false
- },
- axisLabel: {
- interval: 0,
- left: 30,
- inside: true,
- textStyle: {
- color: '#fff',
- fontSize: 14
- },
- show: true
- },
- data: yAxis
- }],
- xAxis: [{
- show: false
- }],
- series: series
- }
- }
- }
- }
- </script>
- <style scoped lang="scss">
- $xHeight: 120px;
- .chart-wrap {
- width: 100%;
- height: 100%;
- .left-bar {
- width: 35px;
- display: inline-block;
- }
- .right-conent {
- width: calc(100% - 35px);
- height: 100%;
- display: grid;
- grid-template-columns: 1fr 1fr 1fr 1fr;
- grid-template-rows: auto $xHeight;
- }
- }
- </style>
|