You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by "banyueyang (via GitHub)" <gi...@apache.org> on 2023/12/28 12:22:12 UTC

[I] [Bug] legend的formatter函数中的 echarts.format.truncateText方法在ts中报错:应有 5 个参数,但获得 4 个。应该如何解决呢 [echarts]

banyueyang opened a new issue, #19447:
URL: https://github.com/apache/echarts/issues/19447

   ### Version
   
   5.4.2
   
   ### Link to Minimal Reproduction
   
   ts兼容问题
   
   ### Steps to Reproduce
   
   const optionPie: EChartsOption = {
           ...basePieOption,
           legend: {
             formatter: function (name) {
               return echarts.format.truncateText(name, 100, '14px Microsoft Yarer', '...');
             },
             tooltip: {
               show: true,
             },
           },
           series: [
             {
               name: '经营异常',
               type: 'pie',
               center: ['35.3%', '50%'],
               radius: [92, 120],
               avoidLabelOverlap: false,
               itemStyle: {
                 borderColor: '#fff',
                 borderWidth: 2,
               },
               label: {
                 show: false,
                 position: 'center',
               },
               tooltip: {
                 formatter(params) {
                   // params.value 为柱状图当前柱子对应的数据值
                   // params.color 为柱状图当前柱子的颜色
                   return `<div style="font-size:13px; font-weight:500;"><span style="display:inline-block;margin-right:8px;border-radius:50%;width:8px;height:8px;background-color:${params.color};"></span>${params.name}<br /><span style="margin-left: 16px;">${formattNumber(params.value)}%</span></div>`;
                 },
                 padding: [8, 10],
               },
               labelLine: {
                 show: false,
               },
               // eslint-disable-next-line max-len
               data:
                 Object.keys(abnormalIData.pieChartDTO?.visualData)?.map((item: any, i: number) => ({
                   name: item,
                   value: abnormalIData.pieChartDTO?.visualData[item],
                   itemStyle: { color: piecolorList[i] || '' },
                 })) || [],
             },
           ],
           graphic: [
             {
               type: 'text',
               left: 323 - textWidth / 2,
               top: 162,
               style: {
                 text: abnormalIData.pieChartDTO?.statisticsShow, // 根据你的需求设置总数值
                 width: 182,
                 fill: '#333',
                 fontSize: 30,
                 fontWeight: 500,
                 fontFamily: 'MiSans-Medium, MiSans',
               },
             },
             {
               type: 'text',
               left: 328 - subTextWidth / 2,
               top: 200,
               style: {
                 text: abnormalIData.pieChartDTO?.statisticsText, // 根据你的需求设置总数值
                 fill: '#666666',
                 fontSize: 14,
               },
             },
           ],
         `};```
   
   ### Current Behavior
   
   我想在react + ts项目中使用echart的legend的formtter函数来做图例的省略号并且hover,但是ts中报错,需要传5个参数,官方例子中只有4个参数,第五个传什么呢
   代码
   echarts.format.truncateText(name, 100, '14px Microsoft Yarer', '...');
   
   ### Expected Behavior
   
   希望能够提供正确的ts中使用方法,
   
   ### Environment
   
   ```markdown
   - OS:macOS Big Sur
   - Browser:Chome 120.0.6099.109
   - Framework: React@18 + Typescript@4.9.5
   ```
   
   
   ### Any additional comments?
   
   _No response_


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org


Re: [I] [Bug] legend的formatter函数中的 echarts.format.truncateText方法在ts中报错:应有 5 个参数,但获得 4 个。应该如何解决呢 [echarts]

Posted by "helgasoft (via GitHub)" <gi...@apache.org>.
helgasoft commented on issue #19447:
URL: https://github.com/apache/echarts/issues/19447#issuecomment-1871427200

   duplicate of #7479


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org


Re: [I] [Bug] legend的formatter函数中的 echarts.format.truncateText方法在ts中报错:应有 5 个参数,但获得 4 个。应该如何解决呢 [echarts]

Posted by "plainheart (via GitHub)" <gi...@apache.org>.
plainheart commented on issue #19447:
URL: https://github.com/apache/echarts/issues/19447#issuecomment-1871885219

   `truncateText` 方法是从 zrender 导出的,可以参考 zrender [源码](https://github.com/ecomfe/zrender/blob/master/src/graphic/helper/parseText.ts)。第五个参数是 `options`,实际上可以省略,后面我们考虑下将最后一个参数变为可选,以避免此类型错误。


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org


Re: [I] [Bug] legend的formatter函数中的 echarts.format.truncateText方法在ts中报错:应有 5 个参数,但获得 4 个。应该如何解决呢 [echarts]

Posted by "echarts-bot[bot] (via GitHub)" <gi...@apache.org>.
echarts-bot[bot] commented on issue #19447:
URL: https://github.com/apache/echarts/issues/19447#issuecomment-1871116734

   @banyueyang It seems you are not using English, I've helped translate the content automatically. To make your issue understood by more people and get helped, we'd like to suggest using English next time. 🤗
   <details><summary><b>TRANSLATED</b></summary><br>
   
   **TITLE**
   
   [Bug] The echarts.format.truncateText method in legend's formatter function reported an error in ts: There should be 5 parameters, but 4 were obtained. How to solve it
   
   **BODY**
   
   ### Version
   
   5.4.2
   
   ### Link to Minimal Reproduction
   
   ts compatibility issues
   
   ### Steps to Reproduce
   
   const optionPie: EChartsOption = {
           ...basePieOption,
           legend: {
             formatter: function (name) {
               return echarts.format.truncateText(name, 100, '14px Microsoft Yarer', '...');
             },
             tooltip: {
               show: true,
             },
           },
           series: [
             {
               name: 'Business abnormality',
               type: 'pie',
               center: ['35.3%', '50%'],
               radius: [92, 120],
               avoidLabelOverlap: false,
               itemStyle: {
                 borderColor: '#fff',
                 borderWidth: 2,
               },
               label: {
                 show: false,
                 position: 'center',
               },
               tooltip: {
                 formatter(params) {
                   // params.value is the data value corresponding to the current column of the histogram
                   // params.color is the color of the current column of the histogram
                   return `<div style="font-size:13px; font-weight:500;"><span style="display:inline-block;margin-right:8px;border-radius:50%;width:8px;height :8px;background-color:${params.color};"></span>${params.name}<br /><span style="margin-left: 16px;">${formattNumber(params.value )}%</span></div>`;
                 },
                 padding: [8, 10],
               },
               labelLine: {
                 show: false,
               },
               // eslint-disable-next-line max-len
               data:
                 Object.keys(abnormalIData.pieChartDTO?.visualData)?.map((item: any, i: number) => ({
                   name: item,
                   value: abnormalIData.pieChartDTO?.visualData[item],
                   itemStyle: { color: piecolorList[i] || '' },
                 })) || [],
             },
           ],
           graphic: [
             {
               type: 'text',
               left: 323 - textWidth / 2,
               top: 162,
               style: {
                 text: abnormalIData.pieChartDTO?.statisticsShow, //Set the total value according to your needs
                 width: 182,
                 fill: '#333',
                 fontSize: 30,
                 fontWeight: 500,
                 fontFamily: 'MiSans-Medium, MiSans',
               },
             },
             {
               type: 'text',
               left: 328 - subTextWidth / 2,
               top: 200,
               style: {
                 text: abnormalIData.pieChartDTO?.statisticsText, //Set the total value according to your needs
                 fill: '#666666',
                 fontSize: 14,
               },
             },
           ],
         `};```
   
   ### Current Behavior
   
   I want to use echart's legend's formtter function in the react + ts project to make the ellipsis and hover of the legend, but an error is reported in ts. 5 parameters need to be passed. There are only 4 parameters in the official example. What is the fifth parameter to pass?
   code
   echarts.format.truncateText(name, 100, '14px Microsoft Yarer', '...');
   
   ### Expected Behavior
   
   I hope to be able to provide the correct usage method in ts,
   
   ### Environment
   
   ```markdown
   - OS: macOS Big Sur
   - Browser:Chome 120.0.6099.109
   - Framework: React@18 + Typescript@4.9.5
   ```
   
   
   ### Any additional comments?
   
   _No response_
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org


Re: [I] [Bug] legend的formatter函数中的 echarts.format.truncateText方法在ts中报错:应有 5 个参数,但获得 4 个。应该如何解决呢 [echarts]

Posted by "Ovilia (via GitHub)" <gi...@apache.org>.
Ovilia closed issue #19447: [Bug] legend的formatter函数中的 echarts.format.truncateText方法在ts中报错:应有 5 个参数,但获得 4 个。应该如何解决呢
URL: https://github.com/apache/echarts/issues/19447


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org