Skip to content

Commit 1aa33b9

Browse files
committed
fixed #2
1 parent 40752bb commit 1aa33b9

File tree

5 files changed

+75
-37
lines changed

5 files changed

+75
-37
lines changed

example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"dependencies": {
1010
"react": "15.3.2",
1111
"react-native": "0.35.0",
12-
"native-echarts": "0.1.0"
12+
"native-echarts": "0.2.0"
1313
},
1414
"jest": {
1515
"preset": "jest-react-native"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "native-echarts",
3-
"version": "0.1.2",
3+
"version": "0.2.0",
44
"description": "echarts for react-native",
55
"main": "src/index.js",
66
"directories": {

src/components/Echarts/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ export default class App extends Component {
88
return (
99
<WebView
1010
scrollEnabled = {false}
11+
injectedJavaScript = {renderChart(this.props)}
1112
style={{
1213
height: this.props.height || 400,
1314
}}
14-
source={{html: renderChart(this.props.option)}}
15+
source={require('./tpl.html')}
1516
/>
1617
);
1718
}

src/components/Echarts/renderChart.js

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,11 @@
11
import echarts from './echarts.min';
22
import toString from '../../util/toString';
33

4-
export default function renderChart(option) {
4+
export default function renderChart(props) {
5+
const height = props.height || 400;
56
return `
6-
<!DOCTYPE html>\n
7-
<html>
8-
<head>
9-
<title>echarts</title>
10-
<meta http-equiv="content-type" content="text/html; charset=utf-8">
11-
<style type="text/css">
12-
html,body {
13-
height: 100%;
14-
width: 100%;
15-
margin: 0;
16-
padding: 0;
17-
overflow: hidden;
18-
}
19-
#main {
20-
height: 100%;
21-
}
22-
</style>
23-
<script>
24-
${echarts}
25-
</script>
26-
</head>
27-
28-
<body>
29-
<div id="main" ></div>
30-
<script>
31-
// 基于准备好的dom,初始化echarts实例
32-
var myChart = echarts.init(document.getElementById('main'));
33-
// 使用刚指定的配置项和数据显示图表。
34-
myChart.setOption(${toString(option)});
35-
</script>
36-
<body>
37-
<html>
38-
`
7+
document.getElementById('main').style.height = "${height}px";
8+
var myChart = echarts.init(document.getElementById('main'));
9+
myChart.setOption(${toString(props.option)});
10+
`
3911
}

src/components/Echarts/tpl.html

Lines changed: 65 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)