mirror of
https://gitee.com/dromara/go-view.git
synced 2025-04-06 03:58:04 +08:00
feat: 新增柱状图图表
This commit is contained in:
parent
49fb0e1113
commit
62f012f2e9
@ -2,17 +2,36 @@ import { getUUID } from '@/utils'
|
|||||||
import { BarCommonConfig } from './index'
|
import { BarCommonConfig } from './index'
|
||||||
|
|
||||||
export default class Config {
|
export default class Config {
|
||||||
id: string = getUUID()
|
private id: string = getUUID()
|
||||||
key: string = BarCommonConfig.key
|
private key: string = BarCommonConfig.key
|
||||||
attr = { x: 0, y: 0, w: 500, h: 300 }
|
public attr = { x: 0, y: 0, w: 500, h: 300 }
|
||||||
|
|
||||||
// 图表配置项
|
// 图表配置项
|
||||||
public config = {
|
public config = {
|
||||||
global: {}
|
backgroundColor: 'rgba(0,0,0,0)',
|
||||||
|
tooltip: {
|
||||||
|
trigger: 'axis',
|
||||||
|
axisPointer: {
|
||||||
|
type: 'shadow'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
xAxis: {
|
||||||
|
type: 'category',
|
||||||
|
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
|
||||||
|
},
|
||||||
|
yAxis: {
|
||||||
|
type: 'value',
|
||||||
|
},
|
||||||
|
series: [
|
||||||
|
{
|
||||||
|
data: [120, 200, 150, 80, 70, 110, 130],
|
||||||
|
type: 'bar',
|
||||||
|
},
|
||||||
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置坐标
|
// 设置坐标
|
||||||
setPosition(x: number, y: number) {
|
public setPosition(x: number, y: number):void {
|
||||||
this.attr.x = x
|
this.attr.x = x
|
||||||
this.attr.y = y
|
this.attr.y = y
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,42 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div :style="wrapperStyle">
|
||||||
这里是柱状图组件渲染
|
<v-chart theme="dark" :option="option" autoresize />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import { computed, toRef, PropType } from 'vue'
|
||||||
|
import VChart from 'vue-echarts'
|
||||||
|
import { use, graphic } from 'echarts/core'
|
||||||
|
import { CanvasRenderer } from 'echarts/renderers'
|
||||||
|
import { BarChart } from 'echarts/charts'
|
||||||
|
import { GridComponent, TooltipComponent, LegendComponent } from 'echarts/components'
|
||||||
|
import config from './config'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
chart: {
|
chartData: {
|
||||||
type: Object,
|
type: Object as PropType<config>,
|
||||||
require: true
|
required: true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
use([
|
||||||
|
CanvasRenderer,
|
||||||
|
BarChart,
|
||||||
|
GridComponent,
|
||||||
|
TooltipComponent,
|
||||||
|
LegendComponent,
|
||||||
|
])
|
||||||
|
|
||||||
|
const option = computed(() => {
|
||||||
|
return props.chartData.config
|
||||||
|
})
|
||||||
|
|
||||||
|
const attr = toRef(props.chartData, 'attr')
|
||||||
|
const wrapperStyle = computed(() => {
|
||||||
|
return {
|
||||||
|
width: `${attr.value.w}px`,
|
||||||
|
height: `${attr.value.h}px`,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
@ -7,7 +7,7 @@ import debounce from 'lodash/debounce'
|
|||||||
* * 生成一个不重复的ID
|
* * 生成一个不重复的ID
|
||||||
* @param { Number } randomLength
|
* @param { Number } randomLength
|
||||||
*/
|
*/
|
||||||
export function getUUID(randomLength: number = 10) {
|
export function getUUID(randomLength = 10) {
|
||||||
return Number(
|
return Number(
|
||||||
Math.random().toString().substr(2, randomLength) + Date.now()
|
Math.random().toString().substr(2, randomLength) + Date.now()
|
||||||
).toString(36)
|
).toString(36)
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
<EditRange>
|
<EditRange>
|
||||||
<!-- 组件名称会重复,必须使用 id -->
|
<!-- 组件名称会重复,必须使用 id -->
|
||||||
<div v-for="item in chartEditStore.getComponentList" :key="item.id">
|
<div v-for="item in chartEditStore.getComponentList" :key="item.id">
|
||||||
<component :is="item.key" />
|
<component :is="item.key" :chartData="item"/>
|
||||||
</div>
|
</div>
|
||||||
</EditRange>
|
</EditRange>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user