GHO*_*OST 5 css jsx reactjs react-native react-native-chart-kit
所以我想在图表上画两条线,我使用 给每条线不同的颜色color。我也想给每条线不同的阴影。但是,通过更改withShadow,它可以同时true适用于两者,也false可以适用于两者,而不能分别适用于每个。我希望我可以为一个数据集使用阴影,而不是另一个数据集,或者为每个数据集使用不同的颜色。
<LineChart
data={{
labels: dataDayOfWeek,
datasets: [
{
data: dataValueNew,
color: `rgba(25, 255, 12, 1)`,
},
{
data: dataValueOld,
color: `rgba(25, 255, 12, 0)`,
withShadow: false, //this did not work
},
],
}}
/>;
Run Code Online (Sandbox Code Playgroud)
小智 3
它有一个非常简单的功能。我也花了一个小时才弄清楚。
ChartConfig 有一个名为 useShadowColorFromDataSet -> Boolean 的字段,这是文档 - https://github.com/indiespirit/react-native-chart-kit
只需在 ChartConfig 中声明它,然后使用数据集中的 Color 字段即可完成。
这是一个示例代码片段 ->
import * as React from 'react';
import { Text, View, StyleSheet } from 'react-native';
import Constants from 'expo-constants';
import {
LineChart,
BarChart,
PieChart,
ProgressChart,
ContributionGraph,
StackedBarChart,
} from 'react-native-chart-kit';
import { Dimensions } from 'react-native';
const screenWidth = Dimensions.get('window').width;
// You can import from local files
import AssetExample from './components/AssetExample';
// or any pure javascript modules available in npm
import { Card } from 'react-native-paper';
export default function App() {
return (
<View>
<Text>Bezier Line Chart</Text>
<LineChart
data={{
labels: ['January', 'February', 'March', 'April', 'May', 'June'],
datasets: [
{
data: [9, 7, 6, 4, 2, 5],
strokeWidth: 2,
color: (opacity = 1) => purple,
// optional
},
{
data: [9, 4, 6, 8, 8, 2],
strokeWidth: 2,
color: (opacity = 1) => black,
colors: 'purple' // optional
},
{
data: [9, 4, 7, 8, 2, 4],
strokeWidth: 3,
color: (opacity = 1) => blue, // optional
},
],
}}
width={Dimensions.get('window').width} // from react-native
height={220}
yAxisLabel="$"
yAxisSuffix="k"
yAxisInterval={1} // optional, defaults to 1
chartConfig={{
backgroundColor: 'grey',
backgroundGradientFrom: 'grey',
backgroundGradientTo: 'grey',
decimalPlaces: 2, // optional, defaults to 2dp
color: (opacity = 1) => rgba(255, 255, 255, ${opacity}),
labelColor: (opacity = 1) => rgba(255, 255, 255, ${opacity}),
style: {
borderRadius: 16,
},
propsForDots: {
r: '',
},
propsForBackgroundLines: {
color: 'black',
stroke: 'black',
strokeDasharray:[],
},
useShadowColorFromDataset: true
}}
bezier
style={{
marginVertical: 8,
borderRadius: 16,
}}
/>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
paddingTop: Constants.statusBarHeight,
backgroundColor: '#ECF0F1',
padding: 8,
},
paragraph: {
margin: 24,
fontSize: 18,
fontWeight: 'bold',
textAlign: 'center',
},
});
Run Code Online (Sandbox Code Playgroud)
嗯,它总是存在于文档中。这教导我们始终正确阅读文档。我花了一个小时才弄清楚。
| 归档时间: |
|
| 查看次数: |
3258 次 |
| 最近记录: |