[英]eCharts Tooltip Typescript
我正在使用 eChart v5.0.2 並使用 Typescript 自定義工具提示,但似乎無法解決有關格式化程序的此錯誤。
所以在 function 關鍵字上,錯誤消息指出: Type '(params: Format | Format[]) => string | Formatter' 不可分配給類型 'string | 格式化程序 | 不明確的'。
在 params.value 上,錯誤是: Type '(params: Format | Format[]) => string | Formatter' 不可分配給類型 'string | 格式化程序 | 不明確的'。
我真的很感激任何幫助,謝謝!
這是我擁有的代碼:
let option: echarts.EChartOption = {
xAxis: {},
yAxis: {},
series: [{
symbolSize: 20,
data: chartData,
type: 'scatter'
}],
tooltip: {
showDelay: 0,
formatter: function (params): (string | echarts.EChartOption.Tooltip.Formatter) {
if (params) {
let xValue = params.value[0];
let yValue = params.value[1];
let dttmValue = params.value[2];
return xValue + yValue + dttmValue;
}
return '';
},
},
};
option && chart.setOption(option);```
It looks like the formatter value is meant to actually BE a echarts.EChartOption.Tooltip.Formatter
function but in your declaration of your formatter function you are effectively saying your formatter property is a function that RETURNS a formatter function.
表示: (string | echarts.EChartOption.Tooltip.Formatter)
的部分是您明確聲明 function 的返回類型的部分。 不是我想的你想要的。
看起來您的格式化程序值要符合的類型在https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/echarts/options/tooltip.d.ts#L390中進行了描述,也就是說should be a function that returns a string so probably : string
to define the return value would be enough - or just return only strings from the function and Typescript will infer that it's the right kind of function to be a formatter.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.