I am trying to use google charts in my react native app.
Below is my code:
import React, {useState, useEffect} from 'react';
import {StyleSheet, View} from 'react-native';
import {WebView} from 'react-native-webview';
import {Chart} from 'react-google-charts';
const ChartScreen = (props: any) => {
const ExampleChart = `
<div className={'my-pretty-chart-container'}>
<Chart
width={'500px'}
height={'300px'}
chartType="PieChart"
loader={<div>Loading Chart</div>}
data={[
['Task', 'Hours per Day'],
['Work', 11],
['Eat', 2],
['Commute', 2],
['Watch TV', 2],
['Sleep', 7],
]}
options={{
title: 'My Daily Activities',
}}
rootProps={{ 'data-testid': '1' }}
/>
</div>`;
return (
<View style={styles.container}>
<WebView source={{html: ExampleChart}} style={styles.webStyle} />
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'space-between',
},
webStyle: {
marginTop: 20,
height: 500,
width: 320,
flex: 1,
},
});
export default ChartScreen;
I am using react-native-webview to display charts from react-google-charts.
But chart is not coming on screen, I don't know what I am doing wrong..!!