占比图数据选择展示
This commit is contained in:
parent
02b9b2f9a1
commit
3d9c54c38a
@ -384,6 +384,10 @@ declare interface ChartBasicStyle {
|
|||||||
* 占比图图形底色
|
* 占比图图形底色
|
||||||
*/
|
*/
|
||||||
proportionBackgroundColor: string
|
proportionBackgroundColor: string
|
||||||
|
/**
|
||||||
|
* 占比图图形展示选择
|
||||||
|
*/
|
||||||
|
proportionSelect:string
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 表头属性
|
* 表头属性
|
||||||
|
@ -96,6 +96,10 @@ const props = defineProps({
|
|||||||
allFields: {
|
allFields: {
|
||||||
type: Array,
|
type: Array,
|
||||||
required: true
|
required: true
|
||||||
|
},
|
||||||
|
allGraphcs:{
|
||||||
|
type: Array,
|
||||||
|
required: true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -279,6 +283,7 @@ watch(
|
|||||||
:property-inner="propertyInnerAll['basic-style-selector']"
|
:property-inner="propertyInnerAll['basic-style-selector']"
|
||||||
:themes="themes"
|
:themes="themes"
|
||||||
:chart="chart"
|
:chart="chart"
|
||||||
|
:allGraphcs = "props.allGraphcs"
|
||||||
@onBasicStyleChange="onBasicStyleChange"
|
@onBasicStyleChange="onBasicStyleChange"
|
||||||
@onMiscChange="onMiscChange"
|
@onMiscChange="onMiscChange"
|
||||||
/>
|
/>
|
||||||
|
@ -41,7 +41,10 @@ const props = defineProps({
|
|||||||
},
|
},
|
||||||
propertyInner: {
|
propertyInner: {
|
||||||
type: Array<string>
|
type: Array<string>
|
||||||
}
|
},
|
||||||
|
allGraphcs: {
|
||||||
|
type: Object
|
||||||
|
},
|
||||||
})
|
})
|
||||||
const showProperty = prop => {
|
const showProperty = prop => {
|
||||||
const has = props.propertyInner?.includes(prop)
|
const has = props.propertyInner?.includes(prop)
|
||||||
@ -369,6 +372,7 @@ onMounted(() => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<el-form size="small" style="width: 100%">
|
<el-form size="small" style="width: 100%">
|
||||||
@ -1483,7 +1487,6 @@ onMounted(() => {
|
|||||||
</el-col>
|
</el-col>
|
||||||
</el-row>
|
</el-row>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="alpha-setting" v-if="showProperty('radius')">
|
<div class="alpha-setting" v-if="showProperty('radius')">
|
||||||
<label class="alpha-label" :class="{ dark: 'dark' === themes }">
|
<label class="alpha-label" :class="{ dark: 'dark' === themes }">
|
||||||
{{ t('chart.pie_outer_radius') }}
|
{{ t('chart.pie_outer_radius') }}
|
||||||
@ -1520,6 +1523,23 @@ onMounted(() => {
|
|||||||
</el-col>
|
</el-col>
|
||||||
</el-row>
|
</el-row>
|
||||||
</div>
|
</div>
|
||||||
|
<!-- 占比图类别隐藏选择 -->
|
||||||
|
<div v-if="showProperty('proportionSelect')"
|
||||||
|
style="margin-bottom:5px;color:#A6A6A6;font-size:12px;">展示数据切换</div>
|
||||||
|
<div class="alpha-setting" v-if="showProperty('proportionSelect')">
|
||||||
|
<el-select
|
||||||
|
:effect="themes"
|
||||||
|
v-model="state.basicStyleForm.proportionSelect"
|
||||||
|
@change="changeBasicStyle('proportionSelect')" clearable
|
||||||
|
>
|
||||||
|
<el-option
|
||||||
|
v-for="item in props.allGraphcs"
|
||||||
|
:key="item.name"
|
||||||
|
:label="item.name"
|
||||||
|
:value="item.name"
|
||||||
|
/>
|
||||||
|
</el-select>
|
||||||
|
</div>
|
||||||
<!-- pie/rose end -->
|
<!-- pie/rose end -->
|
||||||
<!-- circle-packing start -->
|
<!-- circle-packing start -->
|
||||||
<div v-if="showProperty('circleBorderStyle')">
|
<div v-if="showProperty('circleBorderStyle')">
|
||||||
|
@ -63,7 +63,7 @@ import chartViewManager from '@/views/chart/components/js/panel'
|
|||||||
import DatasetSelect from '@/views/chart/components/editor/dataset-select/DatasetSelect.vue'
|
import DatasetSelect from '@/views/chart/components/editor/dataset-select/DatasetSelect.vue'
|
||||||
import { useDraggable } from '@vueuse/core'
|
import { useDraggable } from '@vueuse/core'
|
||||||
import { PluginComponent } from '@/components/plugin'
|
import { PluginComponent } from '@/components/plugin'
|
||||||
import { Field, getFieldByDQ, copyChartField, deleteChartField } from '@/api/chart'
|
import { Field, getFieldByDQ, copyChartField, deleteChartField, getData } from '@/api/chart'
|
||||||
import ChartTemplateInfo from '@/views/chart/components/editor/common/ChartTemplateInfo.vue'
|
import ChartTemplateInfo from '@/views/chart/components/editor/common/ChartTemplateInfo.vue'
|
||||||
import { XpackComponent } from '@/components/plugin'
|
import { XpackComponent } from '@/components/plugin'
|
||||||
import { useEmbedded } from '@/store/modules/embedded'
|
import { useEmbedded } from '@/store/modules/embedded'
|
||||||
@ -983,7 +983,7 @@ const calcData = (view, resetDrill = false, updateQuery = '') => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//更新图表数据
|
||||||
const updateChartData = view => {
|
const updateChartData = view => {
|
||||||
curComponent.value['state'] = 'ready'
|
curComponent.value['state'] = 'ready'
|
||||||
useEmitt().emitter.emit('checkShowEmpty', { allFields: allFields.value, view: view })
|
useEmitt().emitter.emit('checkShowEmpty', { allFields: allFields.value, view: view })
|
||||||
@ -2056,6 +2056,15 @@ const deleteChartFieldItem = id => {
|
|||||||
fieldLoading.value = false
|
fieldLoading.value = false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
const allGraphcs:any = ref([])
|
||||||
|
const tabchange = (val: any) => {
|
||||||
|
if((val.props.label == '样式' || val.props.name == 'style') && view.value.type == 'pie-proportion'){
|
||||||
|
getData(view.value).then(res => {
|
||||||
|
console.log(res.data.data)
|
||||||
|
allGraphcs.value = res.data.data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@ -2141,7 +2150,7 @@ const deleteChartFieldItem = id => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</el-scrollbar>
|
</el-scrollbar>
|
||||||
<el-tabs v-else v-model="tabActive" class="tab-header" :class="{ dark: themes === 'dark' }">
|
<el-tabs v-else v-model="tabActive" class="tab-header" :class="{ dark: themes === 'dark' }" @tab-click="tabchange">
|
||||||
<el-tab-pane name="data" :label="t('chart.chart_data')" class="padding-tab">
|
<el-tab-pane name="data" :label="t('chart.chart_data')" class="padding-tab">
|
||||||
<el-container direction="vertical">
|
<el-container direction="vertical">
|
||||||
<el-scrollbar class="has-footer drag_main_area attr-style theme-border-class">
|
<el-scrollbar class="has-footer drag_main_area attr-style theme-border-class">
|
||||||
@ -2832,7 +2841,7 @@ const deleteChartFieldItem = id => {
|
|||||||
:common-background-pop="curComponent?.commonBackground"
|
:common-background-pop="curComponent?.commonBackground"
|
||||||
:common-border-pop="curComponent?.style" :event-info="curComponent?.events" :chart="view"
|
:common-border-pop="curComponent?.style" :event-info="curComponent?.events" :chart="view"
|
||||||
:themes="themes" :dimension-data="state.dimension" :quota-data="state.quota"
|
:themes="themes" :dimension-data="state.dimension" :quota-data="state.quota"
|
||||||
:all-fields="allFields" @onColorChange="onColorChange" @onMiscChange="onMiscChange"
|
:all-fields="allFields" :all-graphcs="allGraphcs" @onColorChange="onColorChange" @onMiscChange="onMiscChange"
|
||||||
@onLabelChange="onLabelChange" @onTooltipChange="onTooltipChange"
|
@onLabelChange="onLabelChange" @onTooltipChange="onTooltipChange"
|
||||||
@onChangeXAxisForm="onChangeXAxisForm" @onChangeYAxisForm="onChangeYAxisForm"
|
@onChangeXAxisForm="onChangeXAxisForm" @onChangeYAxisForm="onChangeYAxisForm"
|
||||||
@onChangeYAxisExtForm="onChangeYAxisExtForm" @onTextChange="onTextChange"
|
@onChangeYAxisExtForm="onChangeYAxisExtForm" @onTextChange="onTextChange"
|
||||||
|
@ -1778,7 +1778,8 @@ export const DEFAULT_BASIC_STYLE: ChartBasicStyle = {
|
|||||||
circlePadding: 0,
|
circlePadding: 0,
|
||||||
quotaPosition: 'col',
|
quotaPosition: 'col',
|
||||||
quotaColLabel: t('dataset.value'),
|
quotaColLabel: t('dataset.value'),
|
||||||
proportionBackgroundColor:'#ffffff'
|
proportionBackgroundColor:'#ffffff',
|
||||||
|
proportionSelect:''
|
||||||
}
|
}
|
||||||
|
|
||||||
export const BASE_VIEW_CONFIG = {
|
export const BASE_VIEW_CONFIG = {
|
||||||
|
@ -18,7 +18,6 @@ export class RichTextChartView extends AbstractChartView {
|
|||||||
threshold: ['tableThreshold'],
|
threshold: ['tableThreshold'],
|
||||||
'function-cfg': ['emptyDataStrategy']
|
'function-cfg': ['emptyDataStrategy']
|
||||||
}
|
}
|
||||||
debugger
|
|
||||||
axis: AxisType[] = ['xAxis', 'yAxis', 'filter']
|
axis: AxisType[] = ['xAxis', 'yAxis', 'filter']
|
||||||
axisConfig: AxisConfig = {
|
axisConfig: AxisConfig = {
|
||||||
xAxis: {
|
xAxis: {
|
||||||
|
@ -10,7 +10,7 @@ import {
|
|||||||
} from '@/views/chart/components/js/util'
|
} from '@/views/chart/components/js/util'
|
||||||
import { getPadding } from '@/views/chart/components/js/panel/common/common_antv'
|
import { getPadding } from '@/views/chart/components/js/panel/common/common_antv'
|
||||||
import { valueFormatter } from '@/views/chart/components/js/formatter'
|
import { valueFormatter } from '@/views/chart/components/js/formatter'
|
||||||
import { cloneDeep } from 'lodash-es'
|
import { cloneDeep,set } from 'lodash-es'
|
||||||
import isEmpty from 'lodash-es/isEmpty'
|
import isEmpty from 'lodash-es/isEmpty'
|
||||||
import {
|
import {
|
||||||
PIE_AXIS_CONFIG,
|
PIE_AXIS_CONFIG,
|
||||||
@ -18,7 +18,6 @@ import {
|
|||||||
PIE_EDITOR_PROPERTY,
|
PIE_EDITOR_PROPERTY,
|
||||||
PIE_EDITOR_PROPERTY_INNER
|
PIE_EDITOR_PROPERTY_INNER
|
||||||
} from "@/views/chart/components/js/panel/charts/pie/common";
|
} from "@/views/chart/components/js/panel/charts/pie/common";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* G2 Chart 封装器,支持统一销毁和渲染
|
* G2 Chart 封装器,支持统一销毁和渲染
|
||||||
*/
|
*/
|
||||||
@ -63,7 +62,7 @@ export class G2Pie extends G2ChartView {
|
|||||||
] as any
|
] as any
|
||||||
propertyInner: EditorPropertyInner = {
|
propertyInner: EditorPropertyInner = {
|
||||||
...PIE_EDITOR_PROPERTY_INNER,
|
...PIE_EDITOR_PROPERTY_INNER,
|
||||||
'basic-style-selector': ['colors', 'alpha', 'radius','innerRadius', 'seriesColor','proportionBackgroundColor'],
|
'basic-style-selector': ['colors', 'alpha', 'radius','innerRadius', 'seriesColor','proportionBackgroundColor','proportionSelect'],
|
||||||
'tooltip-selector': [...PIE_EDITOR_PROPERTY_INNER['tooltip-selector']],
|
'tooltip-selector': [...PIE_EDITOR_PROPERTY_INNER['tooltip-selector']],
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -78,10 +77,20 @@ export class G2Pie extends G2ChartView {
|
|||||||
const customAttr = parseJson(chart.customAttr)
|
const customAttr = parseJson(chart.customAttr)
|
||||||
const customStyle = parseJson(chart.customStyle)
|
const customStyle = parseJson(chart.customStyle)
|
||||||
const innerRadius = customAttr.basicStyle.innerRadius ?? 60
|
const innerRadius = customAttr.basicStyle.innerRadius ?? 60
|
||||||
const data = cloneDeep(chart.data?.data || [])
|
const initdata = cloneDeep(chart.data?.data || [])
|
||||||
const colorList = customAttr.basicStyle.colors.map(i =>
|
const colorList = customAttr.basicStyle.colors.map(i =>
|
||||||
hexColorToRGBA(i, customAttr.basicStyle.alpha)
|
hexColorToRGBA(i, customAttr.basicStyle.alpha)
|
||||||
)
|
)
|
||||||
|
let templatedata = []
|
||||||
|
if(customAttr.basicStyle.proportionSelect !== ''){
|
||||||
|
initdata.forEach(item=>{
|
||||||
|
if(item.name == customAttr.basicStyle.proportionSelect){
|
||||||
|
templatedata.push(item)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}else{
|
||||||
|
templatedata = initdata
|
||||||
|
}
|
||||||
const g2 = new Chart({
|
const g2 = new Chart({
|
||||||
container,
|
container,
|
||||||
autoFit: true
|
autoFit: true
|
||||||
@ -90,8 +99,15 @@ export class G2Pie extends G2ChartView {
|
|||||||
radius: customAttr.basicStyle.radius / 100,
|
radius: customAttr.basicStyle.radius / 100,
|
||||||
innerRadius: innerRadius / 100
|
innerRadius: innerRadius / 100
|
||||||
})
|
})
|
||||||
|
let resdata = templatedata
|
||||||
g2.data(data)
|
let numbertype = 'number'
|
||||||
|
if(chart.yAxis[0].formatterCfg.type == 'percent'){
|
||||||
|
numbertype = 'percent'
|
||||||
|
resdata.forEach(item => {
|
||||||
|
item.value = parseFloat((item.value * 100).toFixed(2));
|
||||||
|
})
|
||||||
|
}
|
||||||
|
g2.data(resdata)
|
||||||
g2.legend(false)
|
g2.legend(false)
|
||||||
const formatterMap = customAttr.tooltip.seriesTooltipFormatter
|
const formatterMap = customAttr.tooltip.seriesTooltipFormatter
|
||||||
?.filter(i => i.show)
|
?.filter(i => i.show)
|
||||||
@ -100,7 +116,7 @@ export class G2Pie extends G2ChartView {
|
|||||||
return pre
|
return pre
|
||||||
}, {}) as Record<string, SeriesFormatter>
|
}, {}) as Record<string, SeriesFormatter>
|
||||||
if(customAttr.tooltip.show == true){
|
if(customAttr.tooltip.show == true){
|
||||||
this.configTooltip(g2, customAttr, formatterMap);
|
this.configTooltip(g2, customAttr, formatterMap,numbertype);
|
||||||
}else{
|
}else{
|
||||||
g2.tooltip(false)
|
g2.tooltip(false)
|
||||||
}
|
}
|
||||||
@ -141,6 +157,19 @@ export class G2Pie extends G2ChartView {
|
|||||||
}else{
|
}else{
|
||||||
colorval = colorList[0]
|
colorval = colorList[0]
|
||||||
}
|
}
|
||||||
|
if (colorval.startsWith('#')) {
|
||||||
|
colorval = hexColorToRGBA(colorval, customAttr.basicStyle.alpha)
|
||||||
|
}
|
||||||
|
if(customAttr.basicStyle.proportionBackgroundColor.startsWith('#')){
|
||||||
|
customAttr.basicStyle.proportionBackgroundColor = hexColorToRGBA(customAttr.basicStyle.proportionBackgroundColor, customAttr.basicStyle.alpha)
|
||||||
|
}
|
||||||
|
|
||||||
|
if(customAttr.basicStyle.proportionBackgroundColor.startsWith('rgb')){
|
||||||
|
customAttr.basicStyle.proportionBackgroundColor = this.rgbToRgba(customAttr.basicStyle.proportionBackgroundColor,customAttr.basicStyle.alpha)
|
||||||
|
}
|
||||||
|
if(colorval.startsWith('rgb')){
|
||||||
|
colorval = this.rgbToRgba(colorval,customAttr.basicStyle.alpha)
|
||||||
|
}
|
||||||
return name === '其他' ? customAttr.basicStyle.proportionBackgroundColor : colorval;
|
return name === '其他' ? customAttr.basicStyle.proportionBackgroundColor : colorval;
|
||||||
})
|
})
|
||||||
.style({
|
.style({
|
||||||
@ -168,7 +197,7 @@ export class G2Pie extends G2ChartView {
|
|||||||
}else if(item.type == '值' && item.show == true){
|
}else if(item.type == '值' && item.show == true){
|
||||||
view.annotation().text({
|
view.annotation().text({
|
||||||
position: positionarr,
|
position: positionarr,
|
||||||
content: data[0].value,
|
content: chart.yAxis[0].formatterCfg.type == 'percent' ? data[0].value + '%' :data[0].value,
|
||||||
style: {
|
style: {
|
||||||
fontSize: item.fontSize,
|
fontSize: item.fontSize,
|
||||||
fill: item.fill,
|
fill: item.fill,
|
||||||
@ -196,7 +225,7 @@ export class G2Pie extends G2ChartView {
|
|||||||
public setupSeriesColor(chart: ChartObj, data?: any[]): ChartBasicStyle['seriesColor'] {
|
public setupSeriesColor(chart: ChartObj, data?: any[]): ChartBasicStyle['seriesColor'] {
|
||||||
return setUpSingleDimensionSeriesColor(chart, data)
|
return setUpSingleDimensionSeriesColor(chart, data)
|
||||||
}
|
}
|
||||||
protected configTooltip(g2: Chart, customAttr: CustomAttr, formatterMap: Record<string, SeriesFormatter>){
|
protected configTooltip(g2: Chart, customAttr: CustomAttr, formatterMap: Record<string, SeriesFormatter>,numbertype:any){
|
||||||
// 类型断言,确保customAttr是ChartAttr类型
|
// 类型断言,确保customAttr是ChartAttr类型
|
||||||
const attr = customAttr as ChartAttr;
|
const attr = customAttr as ChartAttr;
|
||||||
|
|
||||||
@ -235,7 +264,10 @@ export class G2Pie extends G2ChartView {
|
|||||||
tooltipItems.forEach(item => {
|
tooltipItems.forEach(item => {
|
||||||
const formatter = formatterMap[item.data.quotaList[0].id] ?? (data[0]?.data?.quotaList?.[0] || {})
|
const formatter = formatterMap[item.data.quotaList[0].id] ?? (data[0]?.data?.quotaList?.[0] || {})
|
||||||
const originValue = parseFloat(item.value as string)
|
const originValue = parseFloat(item.value as string)
|
||||||
const value = valueFormatter(originValue, formatter.formatterCfg)
|
let value = valueFormatter(originValue, formatter.formatterCfg)
|
||||||
|
if(numbertype == 'percent'){
|
||||||
|
value = value + '%'
|
||||||
|
}
|
||||||
const name = isEmpty(formatter.chartShowName) ? formatter.name : formatter.chartShowName
|
const name = isEmpty(formatter.chartShowName) ? formatter.name : formatter.chartShowName
|
||||||
tooltipContent += `
|
tooltipContent += `
|
||||||
<div style="display: flex; align-items: center;font-size:${attr.tooltip.fontSize + 'px'};">
|
<div style="display: flex; align-items: center;font-size:${attr.tooltip.fontSize + 'px'};">
|
||||||
@ -269,4 +301,11 @@ export class G2Pie extends G2ChartView {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
protected rgbToRgba(rgb, alpha) {
|
||||||
|
// 提取 RGB 数值
|
||||||
|
const [r, g, b] = rgb.match(/\d+/g).map(Number);
|
||||||
|
|
||||||
|
// 返回 RGBA 格式
|
||||||
|
return `rgba(${r}, ${g}, ${b}, ${Number(alpha)/100})`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user