-
-
Save AudyOdi/72b608e599b724246ad3bce0273ddc18 to your computer and use it in GitHub Desktop.
RN-Chart
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
| /* | |
| Value flicker animation => react-native-ticker | |
| Chart library => victor-native | |
| */ | |
| import React from 'react'; | |
| import { StyleSheet, Text, View } from 'react-native'; | |
| import Ticker, { Tick } from 'react-native-ticker'; | |
| import { | |
| VictoryChart, | |
| VictoryGroup, | |
| VictoryArea, | |
| VictoryScatter, | |
| VictoryCursorContainer, | |
| VictoryTheme, | |
| } from 'victory-native'; | |
| const numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.']; | |
| export default class App extends React.Component { | |
| state = { value: '0.00' }; | |
| render() { | |
| let data = [ | |
| { x: 28, y: 2 }, | |
| { x: 29, y: 3 }, | |
| { x: 30, y: 4 }, | |
| { x: 31, y: 5 }, | |
| { x: 32, y: 6 }, | |
| { x: 33, y: 9 }, | |
| { x: 34, y: 11 }, | |
| { x: 35, y: 13 }, | |
| { x: 36, y: 15 }, | |
| { x: 37, y: 17 }, | |
| { x: 38, y: 22 }, | |
| { x: 39, y: 23 }, | |
| { x: 40, y: 24 }, | |
| ]; | |
| let data2 = [ | |
| { x: 28, y: 12 }, | |
| { x: 29, y: 13 }, | |
| { x: 30, y: 14 }, | |
| { x: 31, y: 15 }, | |
| { x: 32, y: 16 }, | |
| { x: 33, y: 17 }, | |
| { x: 34, y: 18 }, | |
| { x: 35, y: 19 }, | |
| { x: 36, y: 20 }, | |
| { x: 37, y: 21 }, | |
| { x: 38, y: 22 }, | |
| ]; | |
| return ( | |
| <View style={styles.container}> | |
| <Text>Net Worth</Text> | |
| <View style={{ flexDirection: 'row' }}> | |
| <Text style={styles.text}>$</Text> | |
| <Ticker textStyle={styles.text} rotateTime={100}> | |
| {this.state.value.split('').map((char, i) => { | |
| return ( | |
| <Tick key={i} rotateItems={numbers}> | |
| {char} | |
| </Tick> | |
| ); | |
| })} | |
| </Ticker> | |
| </View> | |
| <VictoryChart | |
| theme={VictoryTheme.material} | |
| containerComponent={ | |
| <VictoryCursorContainer | |
| cursorDimension="x" | |
| cursorLabel={() => ''} | |
| onCursorChange={value => { | |
| let value = String((value * 1524 / 100).toFixed(2)); | |
| this.setState({ value }); | |
| }} | |
| /> | |
| } | |
| > | |
| <VictoryGroup | |
| style={{ | |
| data: { strokeWidth: 3, fillOpacity: 0.7 }, | |
| }} | |
| > | |
| <VictoryArea | |
| interpolation={'basis'} | |
| name="area-2" | |
| data={data2} | |
| style={{ | |
| data: { fill: 'magenta', stroke: 'magenta' }, | |
| }} | |
| /> | |
| <VictoryArea | |
| interpolation={'basis'} | |
| name="area-1" | |
| data={data} | |
| style={{ | |
| data: { fill: 'cyan', stroke: 'cyan' }, | |
| }} | |
| /> | |
| </VictoryGroup> | |
| </VictoryChart> | |
| </View> | |
| ); | |
| } | |
| } | |
| const styles = StyleSheet.create({ | |
| container: { | |
| padding: 20, | |
| flex: 1, | |
| backgroundColor: '#fff', | |
| }, | |
| text: { | |
| fontSize: 40, | |
| color: 'black', | |
| }, | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment