簡體   English   中英

使用 react-native-svg-charts 的多折線圖

[英]Multiple Line Charts using 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>
    )
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM