Skip to content

tooltip formatter 使用外部变量的时候,tooltip 会卡死 #117

@lucyanddarlin

Description

@lucyanddarlin

tooltip formatter 使用外部变量的时候,tooltip 会卡死

"react-native-echarts-pro": 1.9.1

      <RNEChartsPro
        option={getChartsOptions(
          units,
          xData,
          yData,
          primaryColor,
          primaryColor
        )}
        height={430}
        webViewSettings={{
          scrollEnabled: false,
        }}
      />
  cosnt getChartsOptions = (
    units: Array<string>,
    xData: Array<string>,
    yData: Array<Array<number>>,
    lineColor: string,
    colorStart: string,
    colorEnd: string = whiteColor
  ) => {
    return {
      xAxis: {
        type: 'category',
        boundaryGap: false,
        data: xData,
      },
      yAxis: {
        type: 'value',
        boundaryGap: [0, '10%'],
        splitLine: {
          show: true,
          lineStyle: {
            type: 'dashed',
          },
        },
      },
      tooltip: {
        trigger: 'axis',
        formatter: function (params: any) {
          let tip = ''
          if (params != null && params.length > 0) {
            tip += params[0].name + '<br />'
            for (let i = 0; i < params.length; i++) {
              let value = params[i].value
              // 在这里使用 units 参数,导致 tooltip 卡死了
              tip += (value ? value.toString() + units[i] : '0') + '<br />'
            }
          }
          return tip
        },
      },
      series: yData.map((y, i) => ({
        type: 'line',
        smooth: true,
        symbol: 'none',
        sampling: 'lttb',
        itemStyle: {
          normal: {
            lineStyle: {
              color: lineColor,
              width: 1.5, //设置线条粗细
            },
          },
        },
        areaStyle: {
          color: {
            type: 'linear',
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [
              {
                offset: 0,
                color: i === 0 ? colorStart : colorEnd, // color at 0%
              },
              {
                offset: 1,
                color: i === 0 ? colorEnd : colorStart, // color at 100%
              },
            ],
            global: false,
          },
        },
        data: y,
      })),
      grid: {
        top: 50,
        bottom: 20,
        left: 20,
      },
    }
  },
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    ToolongNo response for more than two weeks

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions