Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- createChartLabels = (list) => {
- labels = [];
- var moment = require('moment');
- first_date = moment().add(-list.length,'days').format('ll');
- current_date = moment().format('ll');
- labels.push(first_date.substr(0, first_date.indexOf(',')));
- for (i = list.length-1; i > 1; i--) {
- date = moment().add(-i,'days').format('ll');
- label = date.substr(0, date.indexOf(','))
- labels.push(label.slice(-2));
- }
- labels.push(current_date.substr(0, current_date.indexOf(',')));
- return labels;
- }
- const data = this.createChartData(chart_values);
- const labels = this.createChartLabels(data.slice(-7));
- const CustomGrid = ({ x, y, dataPoints, ticks }) => (
- <G>
- {
- // Vertical grid
- dataPoints.map((_, index) => (
- <Line
- key={ index }
- y1={ '0%' }
- y2={ '100%' }
- x1={ x(index) }
- x2={ x(index) }
- stroke={ 'rgba(0,0,0,0.2)' }
- />
- ))
- }
- </G>
- );
- return (
- <TouchableWithoutFeedback onPress={Keyboard.dismiss}>
- <View style={CoinStyles.coinContainerExtended}>
- <AreaChart
- style={ {height: 150, paddingLeft:15, paddingRight:15, paddingTop: 15} }
- contentInset={ { top: 15} }
- dataPoints={data.slice(-7)}
- fillColor={ textWhite }
- animate={false}
- svg={{
- stroke: lineColor,
- strokeWidth: 2,
- fill: darkColor,
- }}
- renderGradient={ ({ id }) => (
- <LinearGradient id={ id } x1={ '0%' } y={ '0%' } x2={ '0%' } y2={ '100%' }>
- <Stop offset={ '0%' } stopColor={ lineColor } stopOpacity={ 0.4 }/>
- <Stop offset={ '100%' } stopColor={ lineColor } stopOpacity={ 0 }/>
- </LinearGradient>
- )}
- curve={shape.curveLinear}
- renderGrid={CustomGrid}
- //renderGrid={ Grid.Vertical }
- />
- <XAxis
- style={ { paddingVertical: 16, paddingLeft:15, paddingRight:15 } }
- values={ labels }
- formatLabel={ (value, index) => value }
- chartType={ XAxis.Type.LINE }
- labelStyle={ { color: lineColor } }
- />
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement