elvinzhu / techarts

An out of the box Taro component for ECharts
69 stars 20 forks source link

通过实例初始化图表,图表未显示 #42

Closed 1zilc closed 3 years ago

1zilc commented 3 years ago

描述

感谢作者的项目,大大方便了我的工作内容 我在使用时发现直接设置option可以渲染,但是通过实例去setOption,会无显示内容

截图

image

代码片段

const Chart = () => {
    const chartRef = useRef<EChart>(null);

    useEffect(() => {
        chartRef.current?.setOption({
            xAxis: {
                type: 'category',
                data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
            },
            yAxis: {
                type: 'value',
            },
            series: [
                {
                    data: [820, 932, 901, 934, 1290, 1330, 1320],
                    type: 'line',
                    smooth: true,
                },
            ],
        });
    }, []);

    return (
        <View style={{ height: 300 }}>
            <EChart ref={chartRef} echarts={echarts} option={{}} />
        </View>
    );
};

版本信息

"@tarojs/cli": "3.3.7", "@tarojs/taro": "3.3.7", "techarts": "^3.0.4", "react": "^17.0.0", "echarts": "5.2.1", 微信库: 2.19.5

1zilc commented 3 years ago

不好意思,初始化option配置有问题,现在已经解决了