我正在尝试使用此示例中的 react-native-svg-charts 向我的面积图添加渐变:https ://github.com/JesperLekland/react-native-svg-charts-examples/blob/master/storybook/故事/面积图/with-gradient.js。
代码编译但我在运行时收到以下错误:
https://imgur.com/nasKm9x(对不起,我还没有足够的声誉来发布图片)
我在我的 Android 手机上使用 Expo。我对编程很陌生,所以我不知道该尝试什么。
import * as shape from 'd3-shape'
import { View } from 'native-base';
import * as React from 'react';
import { AreaChart, Defs, LinearGradient, Path, Stop } from 'react-native-svg-charts'
// import styles from './styles';
class DashboardChart extends React.Component {
render() {
const data = [ 50, 10, 40, 95, 14, 24, 85, 91, 35, 53, 53, 24, 50, 20, 80 ]
const ChartLine = ({line}) => (
<Path
key={'line'}
d={line}
stroke={'rgb(134, 65, 244)'}
fill={'none'}
/>
)
const Gradient = ({ index }) => (
<Defs key={index}>
<LinearGradient id={'gradient'} x1={'0%'} y={'0%'} x2={'0%'} y2={'100%'}>
<Stop offset={'0%'} stopColor="blue" stopOpacity={1}/>
<Stop offset={'100%'} stopColor="white" stopOpacity={1}/>
</LinearGradient>
</Defs>
)
return (
<View>
<AreaChart
style={{ height: 200 }}
data={data}
contentInset={{ top: 40, bottom: 10 }}
curve={shape.curveNatural}
svg={{
fill: 'url(#gradient)'
}}
>
{/* <Grid/> */}
<Gradient/>
<ChartLine/>
</AreaChart>
</View>
);
}
}
export default DashboardChart;