@@ -26,6 +26,7 @@ const ServiceBarChar = ({ customClassNames, dataInfo, height }: ServiceBarCharPr
2626 const [ option , setOption ] = useState < EChartsOption | undefined > ( { } )
2727 // 使用从主题配置中导入的默认颜色,而不是硬编码的颜色值
2828 const [ detaultColor ] = useState ( defaultColor )
29+ const [ hasData , setHasData ] = useState ( true )
2930 const tokenMap = {
3031 inputToken : $t ( '输入 Token' ) ,
3132 outputToken : $t ( '输出 Token' ) ,
@@ -34,7 +35,9 @@ const ServiceBarChar = ({ customClassNames, dataInfo, height }: ServiceBarCharPr
3435 const setChartOption = ( dataInfo : BarChartInfo ) => {
3536 const isNumberArray = typeof dataInfo . data [ 0 ] !== 'object'
3637 const legendData = isNumberArray ? [ dataInfo . title ] : dataInfo . data . map ( ( item ) => item . name )
37- const hasData = dataInfo . data && dataInfo . data . length > 0
38+ const dataExists = dataInfo . data && dataInfo . data . length > 0
39+ // 更新hasData状态
40+ setHasData ( dataExists )
3841 const tooltipFormatter = ( params : { name : string ; color : string ; seriesIndex ?: number } ) => {
3942 let tooltipContent = `<div style="min-width:140px;padding:8px;">
4043 <div>${ isNumberArray ? '' : params . name } </div>`
@@ -73,7 +76,7 @@ const ServiceBarChar = ({ customClassNames, dataInfo, height }: ServiceBarCharPr
7376 rich : {
7477 titleStyle : {
7578 fontSize : 14 ,
76- color : '#999 ' ,
79+ color : '#999999 ' ,
7780 fontWeight : 'normal' ,
7881 lineHeight : 20
7982 } ,
@@ -94,7 +97,7 @@ const ServiceBarChar = ({ customClassNames, dataInfo, height }: ServiceBarCharPr
9497 top : '110px' ,
9598 containLabel : true
9699 } ,
97- tooltip : hasData ? {
100+ tooltip : dataExists ? {
98101 trigger : 'axis' ,
99102 axisPointer : {
100103 type : 'shadow'
@@ -137,9 +140,9 @@ const ServiceBarChar = ({ customClassNames, dataInfo, height }: ServiceBarCharPr
137140 name : '' ,
138141 min : 0 ,
139142 minInterval : 1 ,
140- show : hasData , // 没有数据时不显示Y轴
143+ show : dataExists , // 没有数据时不显示Y轴
141144 splitLine : {
142- show : hasData , // 没有数据时不显示网格线
145+ show : dataExists , // 没有数据时不显示网格线
143146 lineStyle : {
144147 type : 'dashed' ,
145148 color : '#eee'
@@ -179,7 +182,8 @@ const ServiceBarChar = ({ customClassNames, dataInfo, height }: ServiceBarCharPr
179182 // }
180183 // ],
181184 // 添加空状态提示
182- graphic : ! hasData
185+ silent : ! dataExists ,
186+ graphic : ! dataExists
183187 ? [
184188 {
185189 type : 'text' ,
@@ -259,13 +263,15 @@ const ServiceBarChar = ({ customClassNames, dataInfo, height }: ServiceBarCharPr
259263 } , [ ] )
260264 return (
261265 < div className = { `w-full ${ customClassNames } ` } >
262- < ECharts
263- ref = { chartRef }
264- option = { option }
265- style = { { height : height || 400 } }
266- opts = { { renderer : 'svg' } }
267- theme = "apipark" // 这里应用主题名称,需要先在应用入口注册
268- />
266+ < div style = { ! hasData ? { cursor : 'default' , pointerEvents : 'none' } : { } } >
267+ < ECharts
268+ ref = { chartRef }
269+ option = { option }
270+ style = { { height : height || 400 } }
271+ opts = { { renderer : 'svg' } }
272+ theme = "apipark" // 这里应用主题名称,需要先在应用入口注册
273+ />
274+ </ div >
269275 </ div >
270276 )
271277}
0 commit comments