2017-08-04 70 views
0

如何在react-native中創建基本xy圖表?例如我有數據:創建XY圖表,React-Native

chart_data = [ 
[0,0],[0,1],[1,1],[1,0],[0,0] 
] 

這是一個正方形的點。大多數圖書館都提供創建折線圖,這將創建其他線型圖,並且這些點的結果將是 - 飛人。幫幫我,請

回答

0

您可以嘗試使用Canvas及其方法。在那裏,你可以畫點線條或形狀......

1

使用react-native-chart

import React, { StyleSheet, View, Component } from 'react-native'; 
import Chart from 'react-native-chart'; 

const styles = StyleSheet.create({ 
    container: { 
     flex: 1, 
     justifyContent: 'center', 
     alignItems: 'center', 
     backgroundColor: 'white', 
    }, 
    chart: { 
     width: 200, 
     height: 200, 
    }, 
}); 

const data = [ 
    [0, 1], 
    [1, 3], 
    [3, 7], 
    [4, 9], 
]; 

class SimpleChart extends Component { 
    render() { 
     return (
      <View style={styles.container}> 
       <Chart 
        style={styles.chart} 
        data={data} 
        verticalGridStep={5} 
        type="line" 
       /> 
      </View> 
     ); 
    } 
} 

注意MPAndroidChart支持Android只,而反應母語,圖表支持Android和iOS。

示例圖表: enter image description here

+0

我試圖使用該庫。如果我將使用任意形狀的點替換示例中的數據(正如主題中的方格),我將得到我不需要的結果。可能我不理解如何使用該模塊。你能向我解釋我應該如何生成數據點來繪製廣場 – Polly