This commit is contained in:
曹磊 2025-07-16 14:51:29 +08:00
parent 3e9e46ddde
commit e476ec2647
2 changed files with 53 additions and 7 deletions

View File

@ -26,8 +26,25 @@
}, },
customColor: { customColor: {
type: Array, type: Array,
default: () => [], default: () => [ '#018ffb','#ffb74d','#4db6ac','#e57373', '#9575cd', '#a1887f', '#90a4ae', '#4dd0e1', '#81c784', '#ff8a65'],
} },
yAxis: {
type: Object,
default: () => ({type: 'value'}),
},
axisLabel: {
type: Object,
default: () => ({ rotate: 0}),
},
grid: {
type: Object,
default: () => ({
left: '3%',
right: '4%',
bottom: '6%',
containLabel: true
}),
},
}, },
setup(props) { setup(props) {
const chartRef = ref<HTMLDivElement | null>(null); const chartRef = ref<HTMLDivElement | null>(null);
@ -36,20 +53,25 @@
tooltip: { tooltip: {
trigger: 'axis', trigger: 'axis',
axisPointer: { axisPointer: {
type: 'shadow', type: 'cross',
label: { label: {
show: true, show: true,
backgroundColor: '#333', backgroundColor: '#333',
}, },
}, },
}, },
legend: {
data: [],
// orient: 'vertical',
// left: 'top'
},
grid: props.grid,
xAxis: { xAxis: {
type: 'category', type: 'category',
data: [], data: [],
axisLabel: props.axisLabel,
}, },
yAxis: { yAxis: props.yAxis,
type: 'value',
},
series: [ series: [
{ {
name: 'bar', name: 'bar',
@ -78,11 +100,13 @@
//data //data
obj['data'] = chartArr.map((item) => item.value); obj['data'] = chartArr.map((item) => item.value);
obj['type'] = chartArr[0].seriesType; obj['type'] = chartArr[0].seriesType;
obj['yAxisIndex'] = index;
if(props?.customColor && props?.customColor[index]){ if(props?.customColor && props?.customColor[index]){
obj['color'] = props.customColor[index]; obj['color'] = props.customColor[index];
} }
seriesData.push(obj); seriesData.push(obj);
}); });
option.legend.data = typeArr;
option.series = seriesData; option.series = seriesData;
option.xAxis.data = xAxisData; option.xAxis.data = xAxisData;
setOptions(option); setOptions(option);

View File

@ -28,6 +28,22 @@
type: String as PropType<string>, type: String as PropType<string>,
default: 'calc(100vh - 78px)', default: 'calc(100vh - 78px)',
}, },
radius: {
type: Object,
default: () => ['72%'],
},
roseType: {
type: String as PropType<string>,
default: '', //'area'
},
itemStyle: {
type: Object,
default: () => ({ borderRadius: 0}),
},
legend: {
type: Object,
default: () => ({ orient: 'vertical',left: 'top'}),
},
}, },
emits: ['click'], emits: ['click'],
setup(props, { emit }) { setup(props, { emit }) {
@ -37,11 +53,14 @@
tooltip: { tooltip: {
formatter: '{b} ({c})', formatter: '{b} ({c})',
}, },
legend: props.legend,
series: [ series: [
{ {
type: 'pie', type: 'pie',
radius: '72%', radius: props.radius,
center: ['50%', '55%'], center: ['50%', '55%'],
roseType: props.roseType,
itemStyle: props.itemStyle,
data: [], data: [],
labelLine: { show: true }, labelLine: { show: true },
label: { label: {
@ -73,6 +92,9 @@
Object.assign(option, cloneDeep(props.option)); Object.assign(option, cloneDeep(props.option));
} }
option.series[0].data = props.chartData; option.series[0].data = props.chartData;
option.series[0].radius = props.radius;
option.series[0].roseType = props.roseType;
option.series[0].itemStyle = props.itemStyle;
setOptions(option); setOptions(option);
resize(); resize();
getInstance()?.off('click', onClick); getInstance()?.off('click', onClick);