Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用Pyecharts==1.5.1和snapshot-phantomjs==0.0.3运行官方文档中的示例无法生成正确的图片 #5

Open
RuixiangS opened this issue Sep 26, 2019 · 8 comments

Comments

@RuixiangS
Copy link

系统:Win10
IDE:pycharm
python版本:3.6+
pyecharts版本==1.5.1
snapshot-phantomjs==0.0.3
官方示例的代码如下:
`from pyecharts import options as opts
from pyecharts.charts import Bar
from pyecharts.render import make_snapshot

from snapshot_phantomjs import snapshot

def bar_chart() -> Bar:
c = (
Bar()
.add_xaxis(["衬衫", "毛衣", "领带", "裤子", "风衣", "高跟鞋", "袜子"])
.add_yaxis("商家A", [114, 55, 27, 101, 125, 27, 105])
.add_yaxis("商家B", [57, 134, 137, 129, 145, 60, 49])
.reversal_axis()
.set_series_opts(label_opts=opts.LabelOpts(position="right"))
.set_global_opts(title_opts=opts.TitleOpts(title="Bar-测试渲染图片"))
)
return c

make_snapshot(snapshot, bar_chart().render(), "bar0.png")`

产生的报错信息如下:
Traceback (most recent call last):
File "F:/工程/Python/chap02/chart1.py", line 24, in
make_snapshot(snapshot, 'snapshot.html', 'bar1.png')
File "F:\工程\Python\chap02\venv\lib\site-packages\pyecharts\render\snapshot.py", line 39, in make_snapshot
raise OSError(content_array)
OSError: ["ReferenceError: Can't find variable: echarts\n\n undefined:1\nnull\n"]

首先 bar_chart().render() 是可以运行渲染出html在网页中渲染成功的,但是后续这个函数报错我也不知道如何解决了
我通过谷歌查找了一下解决方案仍然没有解决,希望作者能够回复我一下。

@chfw
Copy link
Member

chfw commented Sep 26, 2019

产生的html 可以贴在这吗?

@RuixiangS
Copy link
Author

产生的html 可以贴在这吗?

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Awesome-pyecharts</title>
            <script type="text/javascript" src="https://assets.pyecharts.org/assets/echarts.min.js"></script>

</head>
<body>
    <div id="3a661523ec3e4811accbb578543c7617" class="chart-container" style="width:900px; height:500px;"></div>
    <script>
        var chart_3a661523ec3e4811accbb578543c7617 = echarts.init(
            document.getElementById('3a661523ec3e4811accbb578543c7617'), 'white', {renderer: 'canvas'});
        var option_3a661523ec3e4811accbb578543c7617 = {
    "animation": true,
    "animationThreshold": 2000,
    "animationDuration": 1000,
    "animationEasing": "cubicOut",
    "animationDelay": 0,
    "animationDurationUpdate": 300,
    "animationEasingUpdate": "cubicOut",
    "animationDelayUpdate": 0,
    "color": [
        "#c23531",
        "#2f4554",
        "#61a0a8",
        "#d48265",
        "#749f83",
        "#ca8622",
        "#bda29a",
        "#6e7074",
        "#546570",
        "#c4ccd3",
        "#f05b72",
        "#ef5b9c",
        "#f47920",
        "#905a3d",
        "#fab27b",
        "#2a5caa",
        "#444693",
        "#726930",
        "#b2d235",
        "#6d8346",
        "#ac6767",
        "#1d953f",
        "#6950a1",
        "#918597"
    ],
    "series": [
        {
            "type": "bar",
            "name": "\u5546\u5bb6A",
            "data": [
                114,
                55,
                27,
                101,
                125,
                27,
                105
            ],
            "barCategoryGap": "20%",
            "label": {
                "show": true,
                "position": "right",
                "margin": 8
            },
            "rippleEffect": {
                "show": true,
                "brushType": "stroke",
                "scale": 2.5,
                "period": 4
            }
        },
        {
            "type": "bar",
            "name": "\u5546\u5bb6B",
            "data": [
                57,
                134,
                137,
                129,
                145,
                60,
                49
            ],
            "barCategoryGap": "20%",
            "label": {
                "show": true,
                "position": "right",
                "margin": 8
            },
            "rippleEffect": {
                "show": true,
                "brushType": "stroke",
                "scale": 2.5,
                "period": 4
            }
        }
    ],
    "legend": [
        {
            "data": [
                "\u5546\u5bb6A",
                "\u5546\u5bb6B"
            ],
            "selected": {
                "\u5546\u5bb6A": true,
                "\u5546\u5bb6B": true
            },
            "show": true
        }
    ],
    "tooltip": {
        "show": true,
        "trigger": "item",
        "triggerOn": "mousemove|click",
        "axisPointer": {
            "type": "line"
        },
        "textStyle": {
            "fontSize": 14
        },
        "borderWidth": 0
    },
    "xAxis": [
        {
            "show": true,
            "scale": false,
            "nameLocation": "end",
            "nameGap": 15,
            "gridIndex": 0,
            "inverse": false,
            "offset": 0,
            "splitNumber": 5,
            "minInterval": 0,
            "splitLine": {
                "show": false,
                "lineStyle": {
                    "width": 1,
                    "opacity": 1,
                    "curveness": 0,
                    "type": "solid"
                }
            }
        }
    ],
    "yAxis": [
        {
            "show": true,
            "scale": false,
            "nameLocation": "end",
            "nameGap": 15,
            "gridIndex": 0,
            "inverse": false,
            "offset": 0,
            "splitNumber": 5,
            "minInterval": 0,
            "splitLine": {
                "show": false,
                "lineStyle": {
                    "width": 1,
                    "opacity": 1,
                    "curveness": 0,
                    "type": "solid"
                }
            },
            "data": [
                "\u886c\u886b",
                "\u6bdb\u8863",
                "\u9886\u5e26",
                "\u88e4\u5b50",
                "\u98ce\u8863",
                "\u9ad8\u8ddf\u978b",
                "\u889c\u5b50"
            ]
        }
    ],
    "title": [
        {
            "text": "Bar-\u6d4b\u8bd5\u6e32\u67d3\u56fe\u7247"
        }
    ]
};
        chart_3a661523ec3e4811accbb578543c7617.setOption(option_3a661523ec3e4811accbb578543c7617);
    </script>
</body>
</html>

这个文件在Chrome中打开正常显示的,我试过snapshot-selenium可以正常渲染出图片到工作区,目前就是phantomjs渲染失败...我尝试换过纯英文路径也没有用

@RuixiangS
Copy link
Author

深夜打扰挺不好意思的,回头我请你喝咖啡哈哈哈哈,echarts的图真的很漂亮!

@xyzhong
Copy link

xyzhong commented Jul 18, 2020

linux
/usr/local/lib/python3.6/site-packages/pyecharts/globals.py --> 把echart.min.js下载到本地,同时将globals.py中的js链接修改为本地文件连接 可以解决

@moyunmo
Copy link

moyunmo commented Nov 1, 2021

linux /usr/local/lib/python3.6/site-packages/pyecharts/globals.py --> 把echart.min.js下载到本地,同时将globals.py中的js链接修改为本地文件连接 可以解决

感谢,果然是js应用的问题,放到本地后解决。

@chfw
Copy link
Member

chfw commented Nov 3, 2021

哪你们本地机是不是不能上网?或者是有防火墙,或者是需要proxy server?

@moyunmo
Copy link

moyunmo commented Nov 3, 2021

哪你们本地机是不是不能上网?或者是有防火墙,或者是需要proxy server?

内网服务,访问其他域名正常,引用这个在线的js应用不了。

@chfw
Copy link
Member

chfw commented Nov 3, 2021

哦!那就是 pyecharts 这个线上资源用不了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants