reactjs - 渐变 SVG 在网页上渲染,但不在移动设备上
问题描述
我正在使用 react-native-svg 呈现包含渐变的图表,在 web 上完美运行,但是在 react-native 上使用相同的代码时它不起作用
这是反应本机代码
const data = [
{x: new Date(2000, 3, 2), y: 100},
{x: new Date(2003, 4, 3), y: 120},
{x: new Date(2002, 5, 4), y: 140},
{x: new Date(2005, 6, 5), y: 150},
{x: new Date(2006, 7, 6), y: 130},
{x: new Date(2007, 8, 7), y: 120},
{x: new Date(2008, 9, 8), y: 150},
];
export default function Chart4() {
const dateData = data.map(i => i.x);
return (
<Svg>
<Defs>
<LinearGradient id="myGradient" x1="0" y1="0" x2="0" y2="1.3">
<Stop offset="0%" stopColor="#86CD9B" stop-opacity={1} />
<Stop offset="100%" stopColor="white" stop-opacity={1} />
</LinearGradient>
</Defs>
<VictoryChart scale={{x: 'time', y: 'linear'}}>
<VictoryAxis dependentAxis />
<VictoryAxis
tickValues={dateData}
tickFormat={x => {
return x.toLocaleString('vn-vn', {
month: 'short',
day: 'numeric',
});
}}
/>
<VictoryArea
data={data}
style={{
data: {fill: 'url(#myGradient)'},
}}
/>
<VictoryScatter
data={data}
style={{
data: {
stroke: '#86CD9B',
fill: 'white',
strokeWidth: 1,
fillOpacity: 1,
},
}}
labels={({datum}) =>
`x: ${datum.x.toLocaleString('vn-vn', {
month: 'short',
day: 'numeric',
})} \n y:${datum.y}`
}
labelComponent={
<VictoryTooltip
renderInPortal={false}
dy={0}
centerOffset={{x: 25}}
/>
}
/>
</VictoryChart>
</Svg>
);
}
但是在 web ( react ) 上,它工作得很好,这里是https://codesandbox.io/s/chart-blood-glucose-031dn?file=/src/App.js的codesanbbox
怎么回事,求大神帮忙,万分感谢
解决方案
推荐阅读
- java - 如何修复包名称'android.support.graphics.drawable'用于:com.android.support:animated-vector-drawable:28.0.0
- javascript - 尝试通过 ajax 将表单数据发送到示例 PHP 文件
- c - 从 ncurses FIELD 取回值列表
- asp.net - 是否可以使用 ASP .NET 获取机器 MAC 地址?
- angular - 在 ipAddress 上运行应用程序时未加载应用程序组件
- c# - 获取具有可变长度的某个字符之前和之后的字符
- java - 如果内容中有逗号,则需要在第二列中创建新行,并且第一列需要自动调整大小使用 Java Apache POI
- java - 如何使用杰克逊将 ArrayList 变量转换为 XML 并自行定义根元素
- nativescript - 是否有可能务实地将信息写入IOS钥匙串......?
- spring-webflux - 有没有办法在spring webflux中为特定的url执行WebFilter