我的react-native
应用程序中有一个图表,我想将其转换为 base64 字符串。因此,为此,我想将我LineChart
的转换为图像。那么我该如何实现呢?
import React from 'react';
import {Text, View, Dimensions} from 'react-native';
import {LineChart} from 'react-native-chart-kit';
const App = () => {
return (
<View>
<Text>Bezier Line Chart</Text>
<LineChart
data={{
labels: ['January', 'February', 'March', 'April', 'May', 'June'],
datasets: [
{
data: [
Math.random() * 100,
Math.random() * 100,
Math.random() * 100,
Math.random() * 100,
Math.random() * 100,
Math.random() * 100,
],
},
],
}}
width={Dimensions.get('window').width} // from react-native
height={220}
yAxisLabel="$"
yAxisSuffix="k"
yAxisInterval={1} // optional, defaults to 1
chartConfig={{
backgroundColor: '#e26a00',
backgroundGradientFrom: '#fb8c00',
backgroundGradientTo: '#ffa726',
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: '6',
strokeWidth: '2',
stroke: '#ffa726',
},
}}
bezier
style={{
marginVertical: 8,
borderRadius: 16,
}}
/>
</View>
);
};
export default App;
这是基本的 LineChart 程序。
PS
如果无法使用此软件包,是否有任何其他方法可以将任何数据点转换为图形并因此将其转换为图像?