refactor(echarts): 重构 ECharts 使用方式并优化图表配置- 在 main.js 中引入 ECharts 及相关组件,并通过 Vue.prototype.$echarts 使 ECharts 在全局可用

- 修改 echarts.vue 组件,使用全局的 $echarts 替代局部引入的 echarts
- 优化 overview.vue 中的图表配置,调整颜色渐变和偏移
This commit is contained in:
陈昱达
2025-05-08 09:31:08 +08:00
parent 4179d1cb31
commit 0dea699f1f
3 changed files with 36 additions and 6 deletions

View File

@@ -29,6 +29,36 @@ for (let item in generatedComponents) {
} }
import '@/icons' // icon import '@/icons' // icon
import '@/assets/js/utils/permission' // permission control import '@/assets/js/utils/permission' // permission control
import * as echarts from 'echarts'
// 引入柱状图图表,图表后缀都为 Chart
import { LineChart } from 'echarts/charts'
// 引入标题,提示框,直角坐标系,数据集,内置数据转换器组件,组件后缀都为 Component
import {
TitleComponent,
TooltipComponent,
GridComponent,
DatasetComponent,
TransformComponent
} from 'echarts/components'
// 标签自动布局、全局过渡动画等特性
import { LabelLayout, UniversalTransition } from 'echarts/features'
// 引入 Canvas 渲染器,注意引入 CanvasRenderer 或者 SVGRenderer 是必须的一步
import { CanvasRenderer } from 'echarts/renderers'
// 注册必须的组件
echarts.use([
TitleComponent,
TooltipComponent,
GridComponent,
DatasetComponent,
TransformComponent,
LineChart,
LabelLayout,
UniversalTransition,
CanvasRenderer
])
Vue.prototype.$echarts = echarts
// set ElementUI lang to EN // set ElementUI lang to EN
Vue.use(ElementUI, { locale }) Vue.use(ElementUI, { locale })
//二次封装的el-table //二次封装的el-table

View File

@@ -4,7 +4,7 @@
</div> </div>
</template> </template>
<script> <script>
import * as echarts from 'echarts' // import * as echarts from 'echarts'
import uuid from 'uuid' import uuid from 'uuid'
export default { export default {
@@ -44,11 +44,11 @@ export default {
filters: {}, filters: {},
methods: { methods: {
drawEcharts() { drawEcharts() {
let myChart = echarts.init(document.getElementById(this.echartsId)) let myChart = this.$echarts.init(document.getElementById(this.echartsId))
let option = { let option = {
...this.options ...this.options
} }
myChart.setOption(this.options) myChart.setOption(option)
} }
}, },
created() {}, created() {},

View File

@@ -61,13 +61,13 @@ export default {
color: '#0694A2' color: '#0694A2'
}, },
areaStyle: { areaStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 2, [ color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{ {
offset: 0, offset: 0,
color: '#F3F9FA' color: '#0694A2'
}, },
{ {
offset: 0.2, offset: 1,
color: '#F3F9FA' color: '#F3F9FA'
} }
]) ])