简体   繁体   English

电子图表工具提示 Typescript

[英]eCharts Tooltip Typescript

I'm using eChart v5.0.2 and working to customize the tooltip using Typescript, but can't seem to resolve this error regarding the formatter.我正在使用 eChart v5.0.2 并使用 Typescript 自定义工具提示,但似乎无法解决有关格式化程序的此错误。

So on the function keyword, the error message states: Type '(params: Format | Format[]) => string |所以在 function 关键字上,错误消息指出: Type '(params: Format | Format[]) => string | Formatter' is not assignable to type 'string | Formatter' 不可分配给类型 'string | Formatter |格式化程序 | undefined'.不明确的'。

And on the params.value, the error is: Type '(params: Format | Format[]) => string |在 params.value 上,错误是: Type '(params: Format | Format[]) => string | Formatter' is not assignable to type 'string | Formatter' 不可分配给类型 'string | Formatter |格式化程序 | undefined'.不明确的'。

I would really appreciate any help with this thanks!我真的很感激任何帮助,谢谢!

This is the code that I have:这是我拥有的代码:


            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. 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.

The bit that says : (string | echarts.EChartOption.Tooltip.Formatter) is the part where you explicitly declare the return type of your function.表示: (string | echarts.EChartOption.Tooltip.Formatter)的部分是您明确声明 function 的返回类型的部分。 Not what you intend I think.不是我想的你想要的。

It looks like the type your formatter value is MEANT to conform to is described at https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/echarts/options/tooltip.d.ts#L390 which is to say it 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.看起来您的格式化程序值要符合的类型在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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM