react-native-echarts icon indicating copy to clipboard operation
react-native-echarts copied to clipboard

Pie chart doesnt render first time on IOS

Open RafaelCENG opened this issue 1 year ago • 2 comments

For some reason, my pie chart doesn't render the first time on my view. I have to change the tab for example and come back to show it. This is happening only on IOS and for some reason only on the specific chart. (I have other pie,line etc working perfectly.)

https://github.com/user-attachments/assets/0b9a7223-2ec4-42fc-a40c-590c9bf31748

RafaelCENG avatar Aug 27 '24 14:08 RafaelCENG

It's hard to think of the possible reason. You can add a log to observe the difference between iOS and Android. Is there any corresponding error? Does clicking on a blank area change anything?

zhiqingchen avatar Aug 28 '24 02:08 zhiqingchen

Good morning. Clicking on blank area doesn't do anything. I also have other pies and they are working on IOS except the specific one for some reason on the initial render here is my code for it.

  const pieData = useMemo(() => {
    return sortedStatistics.map((stat, index) => ({
      value: values[index],
      name: stat.positionType,
    }))
  }, [sortedStatistics])

  const pieRef = useRef<any>(null)
  useEffect(() => {
    const PieOptions = {
      series: [
        {
          name: "Positions",
          type: "pie",
          radius: ["20%", "70%"],
          label: {
            show: false,
            position: "center",
          },
          center: ["40%", "50%"],
          data: pieData,
          color: pieChartColors,
        },
      ],
    }
    let chart: any
    if (pieRef.current) {
      chart = echarts.init(pieRef.current, "light", {
        renderer: "svg",
        width: 200,
        height: 250,
      })
      chart.setOption(PieOptions)
      chart.on("mousemove", (params: any) => {
        setPositionName(params.name)
        setValue(params.value)
      })
    }
    return () => chart?.dispose()
  }, [pieData])
  

RafaelCENG avatar Aug 28 '24 06:08 RafaelCENG