11import { BaseG2Chart } from '@/views/chat/component/BaseG2Chart.ts'
22import type { ChartAxis , ChartData } from '@/views/chat/component/BaseChart.ts'
3+ import type { G2Spec } from '@antv/g2'
34
45export class Line extends BaseG2Chart {
56 constructor ( id : string ) {
@@ -17,43 +18,62 @@ export class Line extends BaseG2Chart {
1718 return
1819 }
1920
20- this . chart
21- ?. data ( data )
22- . encode ( 'x' , x [ 0 ] . value )
23- . encode ( 'y' , y [ 0 ] . value )
24- . axis ( {
21+ const options : G2Spec = {
22+ ...this . chart . options ( ) ,
23+ type : 'view' ,
24+ data : data ,
25+ encode : {
26+ x : x [ 0 ] . value ,
27+ y : y [ 0 ] . value ,
28+ color : series . length > 0 ? series [ 0 ] . value : undefined ,
29+ } ,
30+ axis : {
2531 x : { title : x [ 0 ] . name } ,
2632 y : { title : y [ 0 ] . name } ,
27- } )
28- . scale ( 'x' , {
29- nice : true ,
30- } )
31- . scale ( 'y' , {
32- nice : true ,
33- } )
34-
35- if ( series . length > 0 ) {
36- this . chart ?. encode ( 'color' , series [ 0 ] . value )
37- }
38-
39- this . chart
40- ?. line ( )
41- . label ( {
42- text : y [ 0 ] . value ,
43- style : {
44- dx : - 10 ,
45- dy : - 12 ,
33+ } ,
34+ scale : {
35+ x : {
36+ nice : true ,
37+ } ,
38+ y : {
39+ nice : true ,
40+ } ,
41+ } ,
42+ children : [
43+ {
44+ type : 'line' ,
45+ labels : [
46+ {
47+ text : y [ 0 ] . value ,
48+ style : {
49+ dx : - 10 ,
50+ dy : - 12 ,
51+ } ,
52+ transform : [
53+ { type : 'overlapDodgeY' } ,
54+ { type : 'exceedAdjust' } ,
55+ { type : 'overlapHide' } ,
56+ ] ,
57+ } ,
58+ ] ,
59+ tooltip : ( data ) => {
60+ if ( series . length > 0 ) {
61+ return { name : data [ series [ 0 ] . value ] , value : data [ y [ 0 ] . value ] }
62+ } else {
63+ return { name : y [ 0 ] . name , value : data [ y [ 0 ] . value ] }
64+ }
65+ } ,
66+ } ,
67+ {
68+ type : 'point' ,
69+ style : {
70+ fill : 'white' ,
71+ } ,
72+ tooltip : false ,
4673 } ,
47- transform : [ { type : 'overlapDodgeY' } , { type : 'exceedAdjust' } , { type : 'overlapHide' } ] ,
48- } )
49- . tooltip ( ( data ) => {
50- if ( series . length > 0 ) {
51- return { name : data [ series [ 0 ] . value ] , value : data [ y [ 0 ] . value ] }
52- } else {
53- return { name : y [ 0 ] . name , value : data [ y [ 0 ] . value ] }
54- }
55- } )
74+ ] ,
75+ } as G2Spec
5676
57- this . chart ?. point ( ) . style ( 'fill' , 'white' ) . tooltip ( false )
77+ this . chart . options ( options )
5878 }
5979}
0 commit comments