This commit is contained in:
ljx 2025-07-10 11:18:52 +08:00
parent b582b40d5f
commit 10146d32b9
3 changed files with 129 additions and 20 deletions

View File

@ -5,7 +5,29 @@ export const componentList = [
type: 'line-chart', type: 'line-chart',
icon: require('@/assets/chart-line.png'), icon: require('@/assets/chart-line.png'),
groupName: '图表', groupName: '图表',
component: () => import('./elements/chart-line.vue') // 新增组件引用 component: () => import('./elements/chart-line.vue'), // 新增组件引用
props: [
{
name: 'title',
type: 'string',
label: '标题',
default: '线图标题',
group: '基础'
},
{
name: 'dbName',
type: 'string',
label: '数据源对象',
default: '',
group: '数据'
},
],
defaultOption: {
x: 0,
y: 0,
width: 600,
height: 300
}
}, },
{ {
id: 'chart-bar', id: 'chart-bar',
@ -29,7 +51,13 @@ export const componentList = [
default: '', default: '',
group: '数据' group: '数据'
}, },
] ],
defaultOption: {
x: 0,
y: 0,
width: 300,
height: 300
}
}, },
{ {
id: 'chart-pie', id: 'chart-pie',

View File

@ -1,24 +1,56 @@
<template> <template>
<div class="chart-bar"> <div class="chart-bar">
<h3>{{ option }}</h3> <div id="bar-chart" style="width: 100%; height: 100%;"></div>
</div> </div>
</template> </template>
<script> <script>
import * as echarts from 'echarts';
export default { export default {
name: 'ChartBar', name: 'ChartBar',
props: { mounted() {
// this.initBarChart();
option: { },
type: Object, methods: {
default: () => ({}) initBarChart() {
const chartDom = document.getElementById('bar-chart');
if (chartDom) {
const chart = echarts.init(chartDom);
const option = {
title: {
text: '标题',
textStyle: {
color: '#000',
fontSize: 18
},
left: 'center'
},
xAxis: {
type: 'category',
data: ['第1天', '第2天', '第3天', '第4天', '第5天', '第6天', '第7天']
},
yAxis: {
type: 'value'
},
series: [
{
data: [120, 200, 150, 80, 70, 110, 130],
type: 'bar'
}
]
};
chart.setOption(option);
}
} }
} }
} };
</script>
</script>
<style scoped> <style scoped>
.chart-bar { .chart-bar {
/* 组件样式 */ width: 100%;
height: 100%;
} }
</style> </style>

View File

@ -1,25 +1,74 @@
<template> <template>
<div class="chart-line"> <div class="chart-line">
<!-- 线图组件内容 --> <div id="line-chart" style="width: 100%; height: 100%;"></div>
<h3>{{ option }}</h3>
</div> </div>
</template> </template>
<script> <script>
import * as echarts from 'echarts';
export default { export default {
name: 'ChartLine', name: 'ChartLine',
props: { mounted() {
// this.initLineChart();
option: { window.addEventListener('resize', this.handleResize);
type: Object, },
default: () => ({}) beforeUnmount() {
window.removeEventListener('resize', this.handleResize);
},
methods: {
initLineChart() {
const chartDom = document.getElementById('line-chart');
if (!chartDom) return;
const myChart = echarts.init(chartDom);
this.myChart = myChart;
// 30
const data = [];
for (let i = 1; i <= 30; i++) {
data.push(Math.floor(Math.random() * 200) + 50);
}
const option = {
title: {
text: '标题',
left: 'center',
textStyle: {
color: '#000',
fontSize: 18
}
},
xAxis: {
type: 'category',
data: Array.from({ length: 30 }, (_, i) => `${i + 1}`)
},
yAxis: {
type: 'value',
// y
position: 'left',
// y
max: 300
},
series: [{
data: data,
type: 'line'
}]
};
myChart.setOption(option);
},
handleResize() {
if (this.myChart) {
this.myChart.resize();
}
} }
} }
} };
</script> </script>
<style scoped> <style scoped>
.chart-line { .chart-line {
/* 组件样式 */ width: 100%;
height: 100%;
} }
</style> </style>