2025-04-30 17:00:23 +08:00

203 lines
4.6 KiB
Vue

<template>
<custom-echart-column-line :chart-data="state.data" height="100%" :option="state.option" />
</template>
<script setup>
import { reactive } from 'vue';
import * as echarts from 'echarts';
const state = reactive({
data: [
{ value: 103, value1: 208, name: '耿马镇' },
{ value: 72, value1: 157, name: '勐撒镇' },
{ value: 50, value1: 125, name: '勐永镇' },
{ value: 60, value1: 146, name: '孟定镇' },
{ value: 40, value1: 86, name: '勐简乡' },
{ value: 111, value1: 172, name: '贺派乡' },
{ value: 81, value1: 180, name: '四排山乡' },
{ value: 55, value1: 99, name: '芒洪乡' },
{ value: 68, value1: 84, name: '大兴乡' },
],
option: {
grid: {
left: '3%',
right: '10%',
bottom: '10%',
top: '15%',
containLabel: true,
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow',
},
backgroundColor: 'rgba(18, 55, 85, 0.8);',
borderColor: '#35d0c0',
formatter: (data) => {
console.log('data', data);
const params = data[0];
let str = `<div class="custom-echarts-tips">
<span>${params.name}</span><br/>
<span>${params.marker} ${params.data} 万</span><br />
<span>${data[1].marker} ${data[1].data} 万</span>
</div>`;
return str;
},
},
barStyle: {
barWidth: 15,
color: {
type: 'linear',
x: 0,
y: 0,
x2: 0,
y2: 1,
colorStops: [
{ offset: 0, color: '#35D0C0' },
{ offset: 1, color: '#35D0C0' },
],
global: false,
},
},
xAxis: {
type: 'category',
axisTick: {
show: false,
alignWithLabel: false,
interval: 'auto',
inside: false,
length: 5,
lineStyle: {
type: 'solid',
width: 1,
color: 'rgba(28, 158, 222, 1)',
},
},
},
yAxis: [
{
type: 'value',
barWidth: 15,
nameTextStyle: {
color: '#fff',
fontSize: 12,
align: 'center',
padding: [0, 20, 5, 0],
},
axisLabel: {
formatter: '{value}',
color: 'rgba(95, 187, 235, 1)',
textStyle: {
fontSize: 14,
color: '#fff',
lineHeight: 16,
},
},
axisTick: {
show: false,
},
splitLine: {
show: true,
lineStyle: {
color: 'rgba(28, 130, 197, .3)',
type: 'dashed',
},
},
},
{
splitNumber: 5,
type: 'value',
show: false,
nameTextStyle: {
color: '#fff',
fontSize: 12,
align: 'center',
padding: [0, 0, 5, 0],
},
axisLabel: {
show: true,
fontSize: 12,
color: '#fff',
},
axisLine: {
show: false,
},
axisTick: {
show: false,
},
splitLine: {
show: false,
},
},
],
legend: {
itemWidth: 12,
itemHeight: 8,
itemGap: 20,
right: '2%',
top: '3%',
x: 'center',
textStyle: {
fontSize: 14,
color: '#fff',
},
data: ['总产量(吨)', '平均产量(吨)'],
selectedMode: false,
},
series: [
{
name: '总产量(吨)',
type: 'bar',
data: [],
barWidth: '15px',
barGap: '50%',
itemStyle: {
normal: {
borderRadius: [8, 8, 0, 0],
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{
offset: 0,
color: 'rgba(53,208,192,1)',
},
{
offset: 1,
color: 'rgba(53,208,192,0)',
},
]),
},
},
label: {
show: false,
position: 'top',
fontSize: 12,
color: '#F5F5F5',
offset: [0, -5],
formatter: '{c}',
},
},
{
data: [], // 折线图的数据
name: '平均产量(吨)',
type: 'line',
yAxisIndex: 1,
showSymbol: true,
symbolSize: 8,
smooth: true,
symbol: 'circle',
max: 100,
lineStyle: {
normal: {
color: 'rgba(53,208,192,1)',
},
},
itemStyle: {
color: 'rgba(254,249,6,1)',
borderColor: '#fff',
borderWidth: 1,
},
},
],
},
});
</script>