0

I'm trying to create stack chart

but right now I have only the line without the faded background that complete to 100% (I mean that I have only the emphasize line).

for example from the picture in bed 8107 I have right not only the 81% line but I don't have the 19% faded...

How can I added the faded background?

this is my code for the stack chart:

   'use strict'
import React, { Component } from 'react'

import {
 PropTypes,
 View,
 Text,
 Animated,
 StyleSheet,
 TouchableHighlight,
 Dimensions
   } from 'react-native'


export class ComplianceRank extends Component {

 constructor (props) {
super(props)
const data = this.props.data

 }


render () {
return (
  <View style={styles.container}>
    <View style={styles.item}>
      <Text style={styles.label}>Bed 1</Text>
      <View style={styles.data}>
        {
          <Animated.View style={[styles.bar, styles.charColor, {width: 80}]} />
        }
      <Text style={styles.dataNumber}>{80}%</Text>
    </View>
    </View>
    <View style={styles.item}>
      <Text style={styles.label}>Bed 2</Text>
      <View style={styles.data}>
        {
          <Animated.View style={[styles.bar, styles.charColor, {width: 65}]} />
        }
        <Text style={styles.dataNumber}>{65}%</Text>
      </View>
    </View>
    <View style={styles.item}>
      <Text style={styles.label}>Bed 3</Text>
      <View style={styles.data}>
        {
          <Animated.View style={[styles.bar, styles.charColor, {width: 60}]} />
        }
        <Text style={styles.dataNumber}>{60}%</Text>
      </View>
    </View>
    <View style={styles.item}>
      <Text style={styles.label}>Bed 4</Text>
      <View style={styles.data}>
        {
          <Animated.View style={[styles.bar, styles.charColor, {width: 56}]} />
        }
        <Text style={styles.dataNumber}>{56}%</Text>
      </View>
    </View>
    <View style={styles.item}>
      <Text style={styles.label}>Bed 5</Text>
      <View style={styles.data}>
        {
          <Animated.View style={[styles.bar, styles.charColor, {width: 40}]} />
        }
        <Text style={styles.dataNumber}>{40}%</Text>
      </View>
    </View>
    <View style={styles.item}>
      <Text style={styles.label}>Bed 6</Text>
      <View style={styles.data}>
        {
          <Animated.View style={[styles.bar, styles.charColor, {width: 20}]} />
        }
        <Text style={styles.dataNumber}>{20}%</Text>
      </View>
    </View>

  </View>
)
 }
}

 const styles = StyleSheet.create({
    container: {
backgroundColor: '#FFF',
flexDirection: 'column',
display:'flex',
marginTop: 6
  },
 // Item
  item: {
flexDirection: 'row',
marginBottom: 5,
paddingHorizontal: 10
  },
label: {
color: '#CBCBCB',
flex: 1,
fontSize: 12,
position: 'relative',
top: 2
 },
 data: {
flex: 2,
flexDirection: 'row'

 },
dataNumber: {
color: '#CBCBCB',
fontSize: 11
 },
// Bar
 bar: {
alignSelf: 'center',
borderRadius: 5,
height: 20,
marginRight: 5
  },
 charColor: {
backgroundColor: '#6FDEDE'
  },
 charColorFaded: {
backgroundColor: '#d5f6f6'
 }
})

I'm new with react native so I'm sorry if its beginner question.

3
  • all is hard coded, what does this has to do with d3? Commented Oct 18, 2018 at 13:45
  • 1
    @rioV8 you right I took it off Commented Oct 18, 2018 at 14:04
  • 1
    any suggestion? Commented Oct 18, 2018 at 14:44

1 Answer 1

1

Try to wrap the Animated View and change the styles in this way:

  <View style={styles.data}>
    <View style={[styles.bar, styles.charColorFaded]}>
      <Animated.View style={[styles.charColor, {width: 20}]} />
    </View>
    <Text style={styles.dataNumber}>{20}%</Text>
  </View>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.