Advertisement
Guest User

Untitled

a guest
Jan 16th, 2018
400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. createChartLabels = (list) => {
  2.             labels = [];
  3.             var moment = require('moment');
  4.             first_date = moment().add(-list.length,'days').format('ll');
  5.             current_date = moment().format('ll');
  6.             labels.push(first_date.substr(0, first_date.indexOf(',')));
  7.             for (i = list.length-1; i > 1; i--) {
  8.                     date = moment().add(-i,'days').format('ll');
  9.                     label = date.substr(0, date.indexOf(','))
  10.                     labels.push(label.slice(-2));
  11.             }
  12.             labels.push(current_date.substr(0, current_date.indexOf(',')));
  13.             return labels;
  14.         }
  15.  
  16.  
  17.  
  18.  
  19. const data = this.createChartData(chart_values);
  20.         const labels = this.createChartLabels(data.slice(-7));
  21.         const CustomGrid = ({ x, y, dataPoints, ticks }) => (
  22.                 <G>
  23.                         {
  24.                                 // Vertical grid
  25.                                 dataPoints.map((_, index) => (
  26.                                         <Line
  27.                                                 key={ index }
  28.                                                 y1={ '0%' }
  29.                                                 y2={ '100%' }
  30.                                                 x1={ x(index) }
  31.                                                 x2={ x(index) }
  32.                                                 stroke={ 'rgba(0,0,0,0.2)' }
  33.                                         />
  34.                                 ))
  35.                         }
  36.                 </G>
  37.         );
  38.  
  39.         return (
  40.                 <TouchableWithoutFeedback onPress={Keyboard.dismiss}>
  41.             <View style={CoinStyles.coinContainerExtended}>
  42.                 <AreaChart
  43.                     style={ {height: 150, paddingLeft:15, paddingRight:15, paddingTop: 15} }
  44.                     contentInset={ { top: 15} }
  45.                     dataPoints={data.slice(-7)}
  46.                     fillColor={ textWhite }
  47.                     animate={false}
  48.                     svg={{
  49.                             stroke: lineColor,
  50.                             strokeWidth: 2,
  51.                             fill: darkColor,
  52.                         }}
  53.                                     renderGradient={ ({ id }) => (
  54.                             <LinearGradient id={ id } x1={ '0%' } y={ '0%' } x2={ '0%' } y2={ '100%' }>
  55.                                 <Stop offset={ '0%' } stopColor={ lineColor } stopOpacity={ 0.4 }/>
  56.                                 <Stop offset={ '100%' } stopColor={ lineColor } stopOpacity={ 0 }/>
  57.                             </LinearGradient>
  58.                       )}
  59.                     curve={shape.curveLinear}
  60.                                     renderGrid={CustomGrid}
  61.                                     //renderGrid={ Grid.Vertical }
  62.                 />
  63.                             <XAxis
  64.                     style={ { paddingVertical: 16, paddingLeft:15, paddingRight:15 } }
  65.                     values={ labels }
  66.                                         formatLabel={ (value, index) => value }
  67.                     chartType={ XAxis.Type.LINE }
  68.                     labelStyle={ { color: lineColor } }
  69.                 />
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement