I have been using a React Native charting library for my managed Expo app with no problems for quite some time.
Problem: However, something might have changed since 2 months ago (August 2019) as the chart is now showing an empty space. This is true even for a simple Expo app containing just Text
and the chart Chart
(repo linked below).
I suspect this problem is related to React Native's WebView.
Why is the chart no longer rendering, and how can we fix this problem? Thank you!
Repo : https://github.com/nyxynyx/expo-f2chart-problem
Using:
Dev system
Target Device
App.js
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import Chart from 'react-native-f2chart';
const initScript = data =>`
(function(){
chart = new F2.Chart({
id: 'chart',
pixelRatio: window.devicePixelRatio,
});
chart.source(${JSON.stringify(data)}, {
value: {
tickCount: 5,
min: 0
},
date: {
type: 'timeCat',
range: [0, 1],
tickCount: 3
}
});
chart.tooltip({
custom: true,
showXTip: true,
showYTip: true,
snap: true,
onChange: function(obj) {
window.postMessage(stringify(obj))
},
crosshairsType: 'xy',
crosshairsStyle: {
lineDash: [2]
}
});
chart.axis('date', {
label: function label(text, index, total) {
var textCfg = {};
if (index === 0) {
textCfg.textAlign = 'left';
} else if (index === total - 1) {
textCfg.textAlign = 'right';
}
return textCfg;
}
});
chart.line().position('date*value');
chart.render();
})();
`;
export default function App() {
var data = [{
date: "2017-06-05",
value: 116
}, {
date: "2017-06-06",
value: 129
}, {
date: "2017-06-07",
value: 135
}, {
date: "2017-06-08",
value: 86
}, {
date: "2017-06-09",
value: 73
}, {
date: "2017-06-10",
value: 85
}];
return (
<View style={styles.container}>
<Text>My Chart</Text>
<View style={{ height: 350, width: '100%', backgroundColor: '#555' }}>
<Chart initScript={initScript(data)} />
</View>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#ddd',
alignItems: 'center',
justifyContent: 'center',
},
});
Screenshot
The darker grey area is where the Chart
should be, but it is empty instead of showing the chart.
I tried to recreate this problem with Snack, but I think there's something wrong with it because it doesn't install. So I would recommend using another module. These are already validated modules.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.