javascript - 使用react-native-svg-charts的多折线图

标签 javascript reactjs react-native react-native-svg react-native-svg-charts

我试图将显示不同数据的多个折线图放在一张图中,但无法使用react-native-svg-charts在react-native中这样做。

<View style= {{height: 200}}>
      <LineChart 
        style={{ flex:1 }}
                data={this.state.data}
                svg={{ stroke: 'rgb(134, 65, 244)' }}
                contentInset={{ top: 20, bottom: 20 }}
            >
            <Grid/>
      </LineChart>
      <LineChart 
        style={{position: 'absolute'}}
                data={this.state.data1}
                svg={{ stroke: 'rgb(168, 155, 50)' }}
                contentInset={{ top: 20, bottom: 20 }}
            >
            <Grid/>
      </LineChart>
      </View>

上面的代码是我正在尝试的,但无法获得正确的设计,因为我只得到第一个数据的折线图。

谢谢!

最佳答案

render() {

    const data1 = [ 50, 10, 40, 95, -4, -24, 85, 91, 35, 53, -53, 24, 50, -20, -80 ]
    const data2 = [ -87, 66, -69, 92, -40, -61, 16, 62, 20, -93, -54, 47, -89, -44, 18 ]

    const data = [
        {
            data: data1,
            svg: { stroke: '#8800cc' },
        },
        {
            data: data2,
            svg: { stroke: 'green' },
        },
    ]

    return (
        <LineChart
            style={{ height: 200 }}
            data={ data }
            contentInset={{ top: 20, bottom: 20 }}
        >
            <Grid />
        </LineChart>
    )
}

关于javascript - 使用react-native-svg-charts的多折线图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59079119/

相关文章:

javascript - Moment.js : Uncaught TypeError: Cannot read property 'defineLocale' of undefined at moment. js:13

android - 升级到 RN 0.68 后,APK 中缺少 index.android.bundle

android - gms :play-services-vision and firebase 版本冲突

react-native - react native 测试-立即行动

javascript - TypeError : this. $E_0.getElementsByTagName 不是函数

javascript - 仅 Ext Js IE 错误

javascript - Javascript 中的 while 与 setTimeout

reactjs - 使用 React-Apollo 设置 React-Storybooks

javascript - 期望 this.children.props()

javascript - 发生Redux状态更改时,组件不会更新