使用反应原生 svg 图表的多折线图



我正在尝试将多个折线图显示在一个图表中,但无法使用 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>
)
}

最新更新