Skip to content

Commit d6501bc

Browse files
author
xuming06
committed
add pyechart advance demo.
1 parent 90ff08d commit d6501bc

5 files changed

Lines changed: 127 additions & 0 deletions

File tree

32echart/advance_method_click.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
@author:XuMing([email protected])
4+
@description:
5+
"""
6+
from __future__ import unicode_literals
7+
8+
9+
from pyecharts_javascripthon.dom import alert
10+
11+
import pyecharts.echarts.events as events
12+
from pyecharts import Map
13+
14+
def on_click(params):
15+
alert(params.name)
16+
print(params.name)
17+
18+
19+
def test_map_show_label():
20+
# show label
21+
value = [155, 10, 66, 78]
22+
attr = ["福建", "山东", "北京", "上海"]
23+
map = Map("全国地图示例", width=1200, height=600)
24+
map.add("", attr, value, maptype="china", is_label_show=True)
25+
map.on(events.MOUSE_CLICK, on_click)
26+
map.render("click_map.html")
27+
28+
29+
test_map_show_label()
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
@author:XuMing([email protected])
4+
@description:
5+
"""
6+
7+
from __future__ import unicode_literals
8+
9+
from pyecharts import Bar
10+
from pyecharts.conf import PyEchartsConfig
11+
from pyecharts.engine import EchartsEnvironment
12+
from pyecharts.utils import write_utf8_html_file
13+
14+
attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
15+
v1 = [5, 20, 36, 10, 75, 90]
16+
v2 = [10, 25, 8, 60, 20, 80]
17+
bar = Bar("柱状图数据堆叠示例")
18+
bar.add("商家A", attr, v1, is_stack=True)
19+
bar.add("商家B", attr, v2, is_stack=True)
20+
21+
config = PyEchartsConfig(echarts_template_dir='./',
22+
jshost='https://cdn.bootcss.com/echarts/3.6.2')
23+
env = EchartsEnvironment(pyecharts_config=config)
24+
tpl = env.get_template('tpl.html')
25+
26+
html = tpl.render(bar=bar)
27+
write_utf8_html_file('my_tpl_demo2.html', html)

32echart/geo_price_demo.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
@author:XuMing([email protected])
4+
@description:
5+
"""
6+
7+
from pyecharts import Geo
8+
9+
data = [("合肥", 11229), ("武汉", 20273), ("大庆", 5679)]
10+
11+
cities = ["合肥", "武汉", "大庆"]
12+
prices = [11229, 20273, 5679]
13+
14+
geo = Geo(
15+
"全国主要城市房价",
16+
"data from ke.com",
17+
title_color="#fff",
18+
title_pos="center",
19+
width=1200,
20+
height=600,
21+
background_color="#404a59",
22+
)
23+
attr, value = geo.cast(data)
24+
geo.add(
25+
"",
26+
cities,
27+
prices,
28+
visual_range=[5000, 22000],
29+
visual_text_color="#fff",
30+
symbol_size=15,
31+
is_visualmap=True,
32+
)
33+
geo.render("geo_price.html")

32echart/test_utils.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
@author:XuMing([email protected])
4+
@description:
5+
"""
6+
import os
7+
import codecs
8+
9+
def get_default_rendering_file_content(file_name="render.html"):
10+
"""
11+
Simply returns the content render.html
12+
"""
13+
with codecs.open(file_name, "r", "utf-8") as f:
14+
return f.read()
15+
16+
17+
def get_fixture_content(file_name):
18+
fixture_file = os.path.join("fixtures", file_name)
19+
with codecs.open(fixture_file, "r", "utf-8") as f:
20+
return f.read()
21+
22+
23+
def store_fixture_content(file_name, content):
24+
fixture_file = os.path.join("fixtures", file_name)
25+
with codecs.open(fixture_file, "w", "utf-8") as f:
26+
return f.write(content)

32echart/tpl.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="zh-CN">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>自定义模板_my</title>
6+
{{ echarts_js_dependencies(bar) }}
7+
</head>
8+
<body>
9+
{{ echarts_container(bar) }}
10+
{{ echarts_js_content(bar) }}
11+
</body>
12+
</html>

0 commit comments

Comments
 (0)