Skip to content

Commit

Permalink
fixed #2
Browse files Browse the repository at this point in the history
  • Loading branch information
somonus committed Nov 1, 2016
1 parent 40752bb commit 1aa33b9
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 37 deletions.
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"dependencies": {
"react": "15.3.2",
"react-native": "0.35.0",
"native-echarts": "0.1.0"
"native-echarts": "0.2.0"
},
"jest": {
"preset": "jest-react-native"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "native-echarts",
"version": "0.1.2",
"version": "0.2.0",
"description": "echarts for react-native",
"main": "src/index.js",
"directories": {
Expand Down
3 changes: 2 additions & 1 deletion src/components/Echarts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ export default class App extends Component {
return (
<WebView
scrollEnabled = {false}
injectedJavaScript = {renderChart(this.props)}
style={{
height: this.props.height || 400,
}}
source={{html: renderChart(this.props.option)}}
source={require('./tpl.html')}
/>
);
}
Expand Down
40 changes: 6 additions & 34 deletions src/components/Echarts/renderChart.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,11 @@
import echarts from './echarts.min';
import toString from '../../util/toString';

export default function renderChart(option) {
export default function renderChart(props) {
const height = props.height || 400;
return `
<!DOCTYPE html>\n
<html>
<head>
<title>echarts</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<style type="text/css">
html,body {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
overflow: hidden;
}
#main {
height: 100%;
}
</style>
<script>
${echarts}
</script>
</head>
<body>
<div id="main" ></div>
<script>
// 基于准备好的dom,初始化echarts实例
var myChart = echarts.init(document.getElementById('main'));
// 使用刚指定的配置项和数据显示图表。
myChart.setOption(${toString(option)});
</script>
<body>
<html>
`
document.getElementById('main').style.height = "${height}px";
var myChart = echarts.init(document.getElementById('main'));
myChart.setOption(${toString(props.option)});
`
}
65 changes: 65 additions & 0 deletions src/components/Echarts/tpl.html

Large diffs are not rendered by default.

0 comments on commit 1aa33b9

Please sign in to comment.