javascript - 如何在本机反应中向堆栈图表添加褪色背景
问题描述
我正在尝试创建堆栈图
但现在我只有一条没有褪色背景的线,完成到 100%(我的意思是我只有强调线)。
例如,从床上 8107 的图片中,我不仅有正确的 81% 线,而且我没有 19% 褪色......
如何添加褪色的背景?
这是我的堆栈图代码:
'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'
}
})
我是 React Native 的新手,所以如果是初学者的问题,我很抱歉。
解决方案
尝试以这种方式包装动画视图并更改样式:
<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>
推荐阅读
- android - 我无法在 Facebook 中为开发人员更改我的应用设置
- java - 如果 jsonarray 中存在属性值,则获取数组对象
- css - 重置 Blogger 设置的 CSS 样式
- postgresql - phpPgAdmin 使用 select 时显示整个文本值
- ios - WebRTC 视频通话期间无法通过耳机获得音频
- html - 移动元素时获得水平滚动,即使它们没有溢出
- javascript - 我想知道是否有办法找出 element.textContext 是否处于活动状态或 element.innerHTML
- php - HTML/CSS/PHP 使用单选按钮隐藏表单值
- stripe-payments - 如何将 Stripe STPPaymentOptionsViewController 与 Swift 5 集成?
- amazon-web-services - 使用外部数据源在 terraform 中获取实例状态 1/2 或 2/2 的 Boto3 脚本