Created
June 11, 2020 18:01
-
-
Save topherPedersen/8a0f8dec39f2b5a9a79177c424266e20 to your computer and use it in GitHub Desktop.
Basic Line Chart in React-Native with VictoryCharts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from 'react'; | |
| import { | |
| SafeAreaView, | |
| StyleSheet, | |
| ScrollView, | |
| View, | |
| Text, | |
| StatusBar, | |
| } from 'react-native'; | |
| import { | |
| VictoryLine, | |
| VictoryChart, | |
| VictoryTheme, | |
| VictoryContainer, | |
| VictoryAxis, | |
| } from "victory-native"; | |
| class App extends React.Component { | |
| constructor(props) { | |
| super(props); | |
| } | |
| calculateSevenDayHistory() { | |
| // todo: write this method | |
| return { | |
| today: 7.50, | |
| yesterday: 8.99, | |
| twoDaysAgo: 15.49, | |
| threeDaysAgo: 2.09, | |
| fourDaysAgo: 5.99, | |
| fiveDaysAgo: 27.88, | |
| sixDaysAgo: 57.60, | |
| }; | |
| } | |
| render() { | |
| const sevenDayHistory = this.calculateSevenDayHistory(); | |
| return( | |
| <SafeAreaView style={{flex: 100, justifyContent: 'center', alignItems: 'center'}}> | |
| <Text>VictoryApp</Text> | |
| <VictoryChart> | |
| <VictoryLine | |
| containerComponent={<VictoryContainer />} | |
| style={{ | |
| data: { stroke: "#c43a31", strokeWidth: 2}, | |
| parent: { border: "3px solid #ccc"}, | |
| }} | |
| data={[ | |
| { x: "6/4", y: sevenDayHistory.sixDaysAgo }, | |
| { x: "6/5", y: sevenDayHistory.fiveDaysAgo }, | |
| { x: "6/7", y: sevenDayHistory.fourDaysAgo }, | |
| { x: "6/8", y: sevenDayHistory.threeDaysAgo }, | |
| { x: "6/9", y: sevenDayHistory.twoDaysAgo }, | |
| { x: "6/10", y: sevenDayHistory.yesterday }, | |
| { x: "6/11", y: sevenDayHistory.today }, | |
| ]} | |
| /> | |
| </VictoryChart> | |
| </SafeAreaView> | |
| ); | |
| } | |
| } | |
| export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment