fix: 新增图表类型

This commit is contained in:
MTrun 2022-02-02 18:17:45 +08:00
parent 8ef13b6325
commit 0cda041315
14 changed files with 200 additions and 36 deletions

View File

@ -1,4 +1,5 @@
import { getUUID } from '@/utils'
import { echartOptionProfixHandle } from '@/packages/utils/chart'
import { BarCommonConfig } from './index'
import { ConfigType, CreateComponentType } from '@/packages/index.d'
import omit from 'lodash/omit'
@ -12,8 +13,7 @@ export default class Config implements CreateComponentType {
public attr = { x: 0, y: 0, w: 500, h: 300 }
// 图表配置项
public config = {
backgroundColor: 'rgba(0,0,0,0)',
public option = echartOptionProfixHandle({
tooltip: {
trigger: 'axis',
axisPointer: {
@ -33,11 +33,11 @@ export default class Config implements CreateComponentType {
type: 'bar'
}
]
}
})
// 设置坐标
public setPosition(x: number, y: number): void {
this.attr.x = x
this.attr.y = y
}
}
}

View File

@ -1,9 +1,9 @@
<template>
<v-chart theme="dark" :option="option" autoresize />
<VChart theme="dark" :option="option" autoresize />
</template>
<script setup lang="ts">
import { computed, toRef, PropType } from 'vue'
import { computed, PropType } from 'vue'
import VChart from 'vue-echarts'
import { use, graphic } from 'echarts/core'
import { CanvasRenderer } from 'echarts/renderers'
@ -31,11 +31,6 @@ use([
])
const option = computed(() => {
return props.chartData.config
return props.chartData.option
})
const attr = toRef(props.chartData, 'attr')
</script>
<style lang="scss" scoped></style>

View File

@ -1,4 +1,5 @@
import { getUUID } from '@/utils'
import { echartOptionProfixHandle } from '@/packages/utils/chart'
import { BarCrossrangefig } from './index'
import { ConfigType, CreateComponentType } from '@/packages/index.d'
import omit from 'lodash/omit'
@ -12,7 +13,7 @@ export default class Config implements CreateComponentType {
public attr = { x: 0, y: 0, w: 500, h: 300 }
// 图表配置项
public config = {
public option = echartOptionProfixHandle({
backgroundColor: 'rgba(0,0,0,0)',
tooltip: {
trigger: 'axis',
@ -33,7 +34,7 @@ export default class Config implements CreateComponentType {
type: 'bar'
}
]
}
})
// 设置坐标
public setPosition(x: number, y: number): void {

View File

@ -1,9 +1,9 @@
<template>
<v-chart theme="dark" :option="option" autoresize />
<VChart theme="dark" :option="option" autoresize />
</template>
<script setup lang="ts">
import { computed, toRef, PropType } from 'vue'
import { computed, PropType } from 'vue'
import VChart from 'vue-echarts'
import { use, graphic } from 'echarts/core'
import { CanvasRenderer } from 'echarts/renderers'
@ -31,11 +31,8 @@ use([
])
const option = computed(() => {
return props.chartData.config
return props.chartData.option
})
const attr = toRef(props.chartData, 'attr')
</script>
<style lang="scss" scoped></style>

View File

@ -0,0 +1,37 @@
import { getUUID } from '@/utils'
import { echartOptionProfixHandle } from '@/packages/utils/chart'
import { LineCommonConfig } from './index'
import { ConfigType, CreateComponentType } from '@/packages/index.d'
import omit from 'lodash/omit'
export default class Config implements CreateComponentType {
public id: string = getUUID()
public key: string = LineCommonConfig.key
public chartData: Exclude<ConfigType, ['node']> = omit(LineCommonConfig, ['node'])
public attr = { x: 0, y: 0, w: 500, h: 300 }
// 图表配置项
public option = echartOptionProfixHandle({
xAxis: {
type: 'category',
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
},
yAxis: {
type: 'value'
},
series: [
{
data: [150, 230, 224, 218, 135, 147, 260],
type: 'line'
}
]
})
// 设置坐标
public setPosition(x: number, y: number): void {
this.attr.x = x
this.attr.y = y
}
}

View File

@ -0,0 +1,7 @@
<template>
<div>配置项目</div>
</template>
<script setup lang="ts">
</script>

View File

@ -1,13 +1,36 @@
<template>
<div>
line组件渲染
</div>
<VChart theme="dark" :option="option" autoresize />
</template>
<script setup lang="ts">
import { computed, PropType } from 'vue'
import VChart from 'vue-echarts'
import { use, graphic } from 'echarts/core'
import { CanvasRenderer } from 'echarts/renderers'
import { LineChart } from 'echarts/charts'
import {
GridComponent,
TooltipComponent,
LegendComponent
} from 'echarts/components'
import config from './config'
const props = defineProps({
chartData: {
type: Object as PropType<config>,
required: true
}
})
use([
CanvasRenderer,
LineChart,
GridComponent,
TooltipComponent,
LegendComponent
])
const option = computed(() => {
return props.chartData.option
})
</script>
<style lang="scss" scoped>
</style>

View File

@ -0,0 +1,65 @@
import { getUUID } from '@/utils'
import { echartOptionProfixHandle } from '@/packages/utils/chart'
import { PieCommonConfig } from './index'
import { ConfigType, CreateComponentType } from '@/packages/index.d'
import omit from 'lodash/omit'
export default class Config implements CreateComponentType {
public id: string = getUUID()
public key: string = PieCommonConfig.key
public chartData: Exclude<ConfigType, ['node']> = omit(PieCommonConfig, ['node'])
public attr = { x: 0, y: 0, w: 500, h: 300 }
// 图表配置项
public option = echartOptionProfixHandle({
tooltip: {
trigger: 'item'
},
legend: {
top: '5%',
left: 'center'
},
series: [
{
name: 'Access From',
type: 'pie',
radius: ['40%', '70%'],
avoidLabelOverlap: false,
itemStyle: {
borderRadius: 10,
borderColor: '#fff',
borderWidth: 2
},
label: {
show: false,
position: 'center'
},
emphasis: {
label: {
show: true,
fontSize: '40',
fontWeight: 'bold'
}
},
labelLine: {
show: false
},
data: [
{ value: 1048, name: 'Search Engine' },
{ value: 735, name: 'Direct' },
{ value: 580, name: 'Email' },
{ value: 484, name: 'Union Ads' },
{ value: 300, name: 'Video Ads' }
]
}
]
})
// 设置坐标
public setPosition(x: number, y: number): void {
this.attr.x = x
this.attr.y = y
}
}

View File

@ -0,0 +1,7 @@
<template>
<div>配置项目</div>
</template>
<script setup lang="ts">
</script>

View File

@ -5,7 +5,7 @@ import { ChatCategoryEnum, ChatCategoryEnumName } from '../../index.d'
export const PieCommonConfig: ConfigType = {
key: 'VPieCommon',
title: '计量图',
title: '图',
category: ChatCategoryEnum.PIE,
categoryName: ChatCategoryEnumName.PIE,
package: PackagesCategoryEnum.CHARTS,

View File

@ -1,13 +1,36 @@
<template>
<div>
饼图渲染
</div>
<VChart theme="dark" :option="option" autoresize />
</template>
<script setup lang="ts">
import { computed, PropType } from 'vue'
import VChart from 'vue-echarts'
import { use, graphic } from 'echarts/core'
import { CanvasRenderer } from 'echarts/renderers'
import { PieChart } from 'echarts/charts'
import {
GridComponent,
TooltipComponent,
LegendComponent
} from 'echarts/components'
import config from './config'
const props = defineProps({
chartData: {
type: Object as PropType<config>,
required: true
}
})
use([
CanvasRenderer,
PieChart,
GridComponent,
TooltipComponent,
LegendComponent
])
const option = computed(() => {
return props.chartData.option
})
</script>
<style lang="scss" scoped>
</style>

View File

@ -18,7 +18,7 @@ export interface CreateComponentType {
key: string
attr: { x: number; y: number; w: number; h: number }
chartData: ConfigType
config: object
option: object
setPosition: Function
}

View File

@ -0,0 +1,8 @@
/**
* * ECharts option
* @param option
*/
export const echartOptionProfixHandle = (option: any) => {
option['backgroundColor'] = 'rgba(0,0,0,0)'
return option
}

View File

@ -0,0 +1 @@
export * from '@/packages/utils/chart'