def test_echarts_js_dependencies_embed(): env = EchartsEnvironment(pyecharts_config=PyEchartsConfig( jshost=get_resource_dir('templates', 'js', 'echarts'))) tpl = env.from_string('{{ echarts_js_dependencies_embed("echarts") }}') bar = create_demo_bar() html = tpl.render(bar=bar) assert len(html) > 0
def test_echarts_js_dependencies(): env = EchartsEnvironment(pyecharts_config=PyEchartsConfig( jshost='http://localhost/echarts')) tpl = env.from_string('{{ echarts_js_dependencies(bar) }}') bar = create_demo_bar() html = tpl.render(bar=bar) assert '<script type="text/javascript" src="http://localhost/echarts/echarts.min.js"></script>' == html # flake8: noqa
def test_echarts_js_dependencies(): env = EchartsEnvironment(pyecharts_config=PyEchartsConfig() # pyecharts_config=PyEchartsConfig() ) tpl = env.get_template('tpl_demo.html') bar = create_demo_bar() html = tpl.render(bar=bar) # flake8: noqa write_utf8_html_file('my_tpl_demo4.html', html)
def test_echarts_js_dependencies_embed(): env = EchartsEnvironment( pyecharts_config=PyEchartsConfig( jshost=get_resource_dir("templates", "js", "echarts") ) ) tpl = env.from_string('{{ echarts_js_dependencies_embed("echarts") }}') bar = create_demo_bar() html = tpl.render(bar=bar) assert len(html) > 0
def dataframe_line_plot(df, title='', path=None): option = { 'title': { 'text': title, 'left': 'center' }, 'legend': { 'show': True, 'orient': 'vertical', 'right': '9%', 'top': '3%' }, 'xAxis': { 'type': 'time', 'axisLine': { 'onZero': False } }, 'yAxis': { 'axisLine': { 'onZero': False } }, 'dataZoom': [{ 'type': 'slider', 'xAxisIndex': 0, 'start': 0, 'end': 50 }] } time = [ts.timestamp() / 0.001 for ts in df.index] series = [] for channel in df.columns: values = df[channel].values.tolist() data = [(t, x) for t, x in zip(time, values)] series.append({ 'type': 'line', 'showSymbol': False, 'name': channel, 'data': data }) option.update({'series': series}) line_plot = Line() line_plot._option.update(option) conf = PyEchartsConfig(echarts_template_dir='html', jshost='js', force_js_embed=False) env = EchartsEnvironment(pyecharts_config=conf) tpl = env.get_template('template.html') html = tpl.render(chart=line_plot) write_utf8_html_file(path, html)
def test_echarts_js_dependencies(): env = EchartsEnvironment( pyecharts_config=PyEchartsConfig(jshost="http://localhost/echarts") ) tpl = env.from_string("{{ echarts_js_dependencies(bar) }}") bar = create_demo_bar() html = tpl.render(bar=bar) assert ( '<script type="text/javascript" src="http://localhost/echarts/echarts.min.js"></script>' == html ) # flake8: noqa
def genReport(self, filetype="html", timeout=60): attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] v1 = [5, 20, 36, 10, 75, 90] v2 = [10, 25, 8, 60, 20, 80] bar = Bar("柱状图数据堆叠示例") bar.add("商家A", attr, v1, is_stack=True, is_toolbox_show=False) bar.add("商家B", attr, v2, is_stack=True) config = PyEchartsConfig(echarts_template_dir=Report.TEMPLATE_DIR) env = EchartsEnvironment(pyecharts_config=config) tpl = env.get_template(Report.REPORT_HTML) html = tpl.render(bar=bar) name = 'report_%s'%self.getUID() write_utf8_html_file("%s/%s.html"%(Report.OUT_DIR, name), html) if "pdf"==filetype: cmd = "phantomjs make_pdf.js %s"%name self.PopenWithTimeout(cmd, cwd=Report.OUT_DIR, timeout=timeout)
def test_echarts_js_in_first(): value = [20, 190, 253, 77, 65] attr = ['汕头市', '汕尾市', '揭阳市', '阳江市', '肇庆市'] map = Map("广东地图示例", width=1200, height=600) map.add("", attr, value, maptype='广东', is_visualmap=True, visual_text_color='#000') env = EchartsEnvironment(pyecharts_config=PyEchartsConfig( jshost='http://localhost/echarts')) tpl = env.from_string('{{ echarts_js_dependencies(m) }}') html = tpl.render(m=map) echarts_js_pos = html.find('echarts.min.js') guangdong_js_pos = html.find('guangdong.js') assert echarts_js_pos > -1 assert guangdong_js_pos > -1 assert echarts_js_pos < guangdong_js_pos
def test_echarts_js_in_first(): value = [20, 190, 253, 77, 65] attr = ["汕头市", "汕尾市", "揭阳市", "阳江市", "肇庆市"] map = Map("广东地图示例", width=1200, height=600) map.add( "", attr, value, maptype="广东", is_visualmap=True, visual_text_color="#000", ) env = EchartsEnvironment(pyecharts_config=PyEchartsConfig( jshost="http://localhost/echarts")) tpl = env.from_string("{{ echarts_js_dependencies(m) }}") html = tpl.render(m=map) echarts_js_pos = html.find("echarts.min.js") guangdong_js_pos = html.find("guangdong.js") assert echarts_js_pos > -1 assert guangdong_js_pos > -1 assert echarts_js_pos < guangdong_js_pos
def test_echarts_js_in_first(): value = [20, 190, 253, 77, 65] attr = ["汕头市", "汕尾市", "揭阳市", "阳江市", "肇庆市"] map = Map("广东地图示例", width=1200, height=600) map.add( "", attr, value, maptype="广东", is_visualmap=True, visual_text_color="#000", ) env = EchartsEnvironment( pyecharts_config=PyEchartsConfig(jshost="http://localhost/echarts") ) tpl = env.from_string("{{ echarts_js_dependencies(m) }}") html = tpl.render(m=map) echarts_js_pos = html.find("echarts.min.js") guangdong_js_pos = html.find("guangdong.js") assert echarts_js_pos > -1 assert guangdong_js_pos > -1 assert echarts_js_pos < guangdong_js_pos
# coding=utf8 """ Test cases for jinja2 template functions """ from __future__ import unicode_literals from nose.tools import raises from pyecharts.utils import get_resource_dir from pyecharts import Bar, Map from pyecharts.engine import BaseEnvironment, EchartsEnvironment from pyecharts.conf import PyEchartsConfig ECHARTS_ENV = EchartsEnvironment() def create_demo_bar(chart_id_demo=None): attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] v1 = [5, 20, 36, 10, 75, 90] v2 = [10, 25, 8, 60, 20, 80] bar = Bar("柱状图数据堆叠示例") bar.add("商家A", attr, v1, is_stack=True) bar.add("商家B", attr, v2, is_stack=True) if chart_id_demo: bar._chart_id = chart_id_demo return bar def test_echarts_js_dependencies(): env = EchartsEnvironment(pyecharts_config=PyEchartsConfig( jshost='http://localhost/echarts'))
from pyecharts import Line from pyecharts.conf import PyEchartsConfig from pyecharts.engine import EchartsEnvironment from pyecharts.utils import write_utf8_html_file from pyecharts import ThemeRiver attr = ['a', 'b', 'c', 'd'] v1 = [40000, 50000, 60000, 70000] pie = Pie("饼图-星级玫瑰图示例", title_pos='center', width=900) pie.add("7-17", attr, v1, center=[75, 50], is_random=True, radius=[30, 75], rosetype='area', is_legend_show=False, is_label_show=True) #pie.render() config = PyEchartsConfig(echarts_template_dir='./') env = EchartsEnvironment(pyecharts_config=config) #tpl = env.get_template('chart_template.html') #html = tpl.render(pie=pie) write_utf8_html_file('chart_out.tif') ## from pyecharts import Gauge gauge = Gauge("仪表盘示例") gauge.add("业务指标", "完成率", 66.66) gauge.show_config() gauge.render()
# -*- coding: utf-8 -*- """ @author:XuMing([email protected]) @description: """ from __future__ import unicode_literals from pyecharts import Bar from pyecharts.conf import PyEchartsConfig from pyecharts.engine import EchartsEnvironment from pyecharts.utils import write_utf8_html_file attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] v1 = [5, 20, 36, 10, 75, 90] v2 = [10, 25, 8, 60, 20, 80] bar = Bar("柱状图数据堆叠示例") bar.add("商家A", attr, v1, is_stack=True) bar.add("商家B", attr, v2, is_stack=True) config = PyEchartsConfig(echarts_template_dir='./', jshost='https://cdn.bootcss.com/echarts/3.6.2') env = EchartsEnvironment(pyecharts_config=config) tpl = env.get_template('tpl.html') html = tpl.render(bar=bar) write_utf8_html_file('my_tpl_demo2.html', html)
# coding=utf8 from __future__ import unicode_literals from pyecharts import Bar from pyecharts.conf import PyEchartsConfig from pyecharts.engine import EchartsEnvironment from pyecharts.utils import write_utf8_html_file attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] v1 = [5, 20, 36, 10, 75, 90] v2 = [10, 25, 8, 60, 20, 80] bar = Bar("柱状图数据堆叠示例") bar.add("商家A", attr, v1, is_stack=True) bar.add("商家B", attr, v2, is_stack=True) config = PyEchartsConfig(echarts_template_dir='my_tpl', jshost='https://cdn.bootcss.com/echarts/3.6.2') env = EchartsEnvironment(pyecharts_config=config) tpl = env.get_template('tpl_demo.html') html = tpl.render(bar=bar) write_utf8_html_file('my_tpl_demo2.html', html)
from __future__ import unicode_literals from pyecharts import Bar from pyecharts.conf import PyEchartsConfig from pyecharts.engine import EchartsEnvironment from pyecharts.utils import write_utf8_html_file attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] v1 = [5, 20, 36, 10, 75, 90] v2 = [10, 25, 8, 60, 20, 80] bar = Bar("柱状图数据堆叠示例") bar.add("商家A", attr, v1, is_stack=True) bar.add("商家B", attr, v2, is_stack=True) config = PyEchartsConfig(echarts_template_dir='my_tpl', jshost='https://cdn.bootcss.com/echarts/3.6.2') env = EchartsEnvironment(pyecharts_config=config) tpl = env.get_template(r'D:\python\tpl_demo.html') html = tpl.render(bar=bar) write_utf8_html_file('my_tpl_demo2.html', html)