File tree Expand file tree Collapse file tree 1 file changed +23
-2
lines changed
frontend/src/views/chat/component/charts Expand file tree Collapse file tree 1 file changed +23
-2
lines changed Original file line number Diff line number Diff line change 11import { BaseG2Chart } from '@/views/chat/component/BaseG2Chart.ts'
22import type { ChartAxis , ChartData } from '@/views/chat/component/BaseChart.ts'
33import type { G2Spec } from '@antv/g2'
4+ import { endsWith , replace } from 'lodash-es'
45
56export class Pie extends BaseG2Chart {
67 constructor ( id : string ) {
@@ -16,12 +17,31 @@ export class Pie extends BaseG2Chart {
1617 return
1718 }
1819
20+ // 特殊处理 %
21+ const _data = [ ]
22+ let isPercent = false
23+ if ( data . length > 0 ) {
24+ const v = data [ 0 ] [ y [ 0 ] . value ] + ''
25+ if ( endsWith ( v , '%' ) ) {
26+ isPercent = true
27+ }
28+ }
29+ for ( let i = 0 ; i < data . length ; i ++ ) {
30+ const v = data [ i ]
31+ const _v = { ...v }
32+ if ( isPercent ) {
33+ const formatValue = replace ( v [ y [ 0 ] . value ] , '%' , '' )
34+ _v [ y [ 0 ] . value ] = Number ( formatValue )
35+ }
36+ _data . push ( _v )
37+ }
38+
1939 const options : G2Spec = {
2040 ...this . chart . options ( ) ,
2141 type : 'interval' ,
2242 coordinate : { type : 'theta' , outerRadius : 0.8 } ,
2343 transform : [ { type : 'stackY' } ] ,
24- data : data ,
44+ data : _data ,
2545 encode : {
2646 y : y [ 0 ] . value ,
2747 color : series [ 0 ] . value ,
@@ -32,7 +52,8 @@ export class Pie extends BaseG2Chart {
3252 labels : [
3353 {
3454 position : 'outside' ,
35- text : ( data : any ) => `${ data [ series [ 0 ] . value ] } : ${ data [ y [ 0 ] . value ] } ` ,
55+ text : ( data : any ) =>
56+ `${ data [ series [ 0 ] . value ] } : ${ data [ y [ 0 ] . value ] } ${ isPercent ? '%' : '' } ` ,
3657 } ,
3758 ] ,
3859 tooltip : ( data ) => {
You can’t perform that action at this time.
0 commit comments