Skip to content

pyechart 配置 formatter 后,生成图片失败 #7

@sigma65535

Description

@sigma65535

snapshot-phantomjs 0.0.3
pyecharts 1.9.0
生成的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="769999bc905c4e638c19691647916950" class="chart-container" style="width:900px; height:500px;"></div>
    <script>
        var chart_769999bc905c4e638c19691647916950 = echarts.init(
            document.getElementById('769999bc905c4e638c19691647916950'), 'white', {renderer: 'canvas'});
        var option_769999bc905c4e638c19691647916950 = {
    "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": "line",
            "name": "nike",
            "connectNulls": false,
            "symbolSize": 4,
            "showSymbol": true,
            "smooth": true,
            "clip": true,
            "step": false,
            "data": [
                [
                    "2020-08\u6708",
                    240346
                ],
                [
                    "2020-09\u6708",
                    791508
                ],
                [
                    "2020-10\u6708",
                    556970
                ],
                [
                    "2020-11\u6708",
                    622863
                ],
                [
                    "2020-12\u6708",
                    426895
                ],
                [
                    "2021-01\u6708",
                    679772
                ],
                [
                    "2021-02\u6708",
                    385812
                ],
                [
                    "2021-03\u6708",
                    1169698
                ],
                [
                    "2021-04\u6708",
                    370846
                ],
                [
                    "2021-05\u6708",
                    234767
                ],
                [
                    "2021-06\u6708",
                    238117
                ],
                [
                    "2021-07\u6708",
                    36476
                ],
                [
                    "2021-08\u6708",
                    0
                ]
            ],
            "hoverAnimation": true,
            "label": {
                "show": false,
                "position": "top",
                "margin": 8
            },
            "lineStyle": {
                "show": true,
                "width": 5,
                "opacity": 1,
                "curveness": 0,
                "type": "solid"
            },
            "areaStyle": {
                "opacity": 0
            },
            "zlevel": 0,
            "z": 0
        }
    ],
    "legend": [
        {
            "data": [
                "nike"
            ],
            "selected": {
                "nike": true
            },
            "show": true,
            "padding": 5,
            "itemGap": 10,
            "itemWidth": 25,
            "itemHeight": 14
        }
    ],
    "tooltip": {
        "show": true,
        "trigger": "axis",
        "triggerOn": "mousemove|click",
        "axisPointer": {
            "type": "cross"
        },
        "showContent": true,
        "alwaysShowContent": false,
        "showDelay": 0,
        "hideDelay": 100,
        "textStyle": {
            "fontSize": 14
        },
        "borderWidth": 0,
        "padding": 5
    },
    "xAxis": [
        {
            "show": true,
            "scale": false,
            "nameLocation": "end",
            "nameGap": 15,
            "gridIndex": 0,
            "inverse": false,
            "offset": 0,
            "splitNumber": 5,
            "minInterval": 0,
            "splitLine": {
                "show": true,
                "lineStyle": {
                    "show": true,
                    "width": 1,
                    "opacity": 1,
                    "curveness": 0,
                    "type": "dashed"
                }
            },
            "splitArea": {
                "show": true,
                "areaStyle": {
                    "opacity": 0
                }
            },
            "data": [
                "2020-08\u6708",
                "2020-09\u6708",
                "2020-10\u6708",
                "2020-11\u6708",
                "2020-12\u6708",
                "2021-01\u6708",
                "2021-02\u6708",
                "2021-03\u6708",
                "2021-04\u6708",
                "2021-05\u6708",
                "2021-06\u6708",
                "2021-07\u6708",
                "2021-08\u6708"
            ]
        }
    ],
    "yAxis": [
        {
            "type": "value",
            "show": true,
            "scale": false,
            "nameLocation": "end",
            "nameGap": 15,
            "gridIndex": 0,
            "axisLabel": {
                "show": true,
                "position": "top",
                "margin": 8,
                "formatter": function format(s) {const locale = 'en-zh';const truncate = false;const precision = 1;const showLessThan = true;function formatNumberStandard (s, precision, separator = ',') {let num = s;num = (typeof precision !== 'undefined' && s % 1 !== 0 ? num.toFixed(precision) : num).toString();const parts = num.split('.');parts[0] = parts[0].toString().replace(/(\\d)(?=(\\d{3})+(?!\\d))/g, `$1${separator}`);return parts.join('.');};  function getSubStrNum (number, dividend, precision, truncate) {let num = number / dividend;if (truncate) {num = Math.floor(num * Math.pow(10, precision + 1)) / Math.pow(10, precision + 1);num = num.toString();} else {num = num.toFixed(precision + 1);}let strNum = num.length - 1;if (precision === 0) {strNum = num.length - 2;}return num.substr(0, strNum);};if (s === 0) {  return '0';}if(showLessThan) {  if (s < 0.01 && s > -0.01) {return '< 0.01';  }  if (s < 0.1 && s > -0.1) {return '< 0.1';  }}const bUnit = 1e9;const mUnit = 1e6;const kUnit = 1000;const yiUnit = 1e8;const wanUnit = 10000;if ((s >= 1000 && s < 10000) || ((s <= -1000 && s > -10000))) {  switch (locale) {case 'en-zh':  return `${getSubStrNum(s, kUnit, 1, truncate)}K`;case 'en-zh_CN':  return `${getSubStrNum(s, kUnit, 1, truncate)}K`;case 'zh-zh':  return formatNumberStandard(s, 1);case 'zh_CN-zh_CN':  return formatNumberStandard(s, 1);default:  return formatNumberStandard(s, 1);  }}if ((s >= 10000 && s < 100000) || (s <= -10000 && s > -100000)) {  switch (locale) {case 'en-zh':  return `${getSubStrNum(s, kUnit, 0, truncate)}K`;case 'en-zh_CN':  return `${getSubStrNum(s, kUnit, 0, truncate)}K`;case 'zh-zh':  return `${getSubStrNum(s, wanUnit, 1, truncate)}\u842c`;case 'zh_CN-zh_CN':  return `${getSubStrNum(s, wanUnit, 1, truncate)}\u4e07`;default:  return formatNumberStandard(s, 1);  }}if ((s >= 100000 && s < 1000000) || (s <= -100000 && s > -1000000)) {  switch (locale) {case 'en-zh':  return `${getSubStrNum(s, kUnit, 0, truncate)}K`;case 'en-zh_CN':  return `${getSubStrNum(s, kUnit, 0, truncate)}K`;case 'zh-zh':  return `${getSubStrNum(s, wanUnit, 0, truncate)}\u842c`;case 'zh_CN-zh_CN':  return `${getSubStrNum(s, wanUnit, 0, truncate)}\u4e07`;default:  return formatNumberStandard(s, 1);  }}if ((s >= 1000000 && s < 10000000) || (s <= -1000000 && s > -10000000)) {  switch (locale) {case 'en-zh':  return `${getSubStrNum(s, mUnit, 1, truncate)}M`;case 'en-zh_CN':  return `${getSubStrNum(s, mUnit, 1, truncate)}M`;case 'zh-zh':  return `${getSubStrNum(s, wanUnit, 0, truncate)}\u842c`;case 'zh_CN-zh_CN':  return `${getSubStrNum(s, wanUnit, 0, truncate)}\u4e07`;default:  return formatNumberStandard(s, 1);  }}if ((s >= 10000000 && s < 1000000000) || (s <= -10000000 && s > -1000000000)) {  switch (locale) {case 'en-zh':  return `${getSubStrNum(s, mUnit, 0, truncate)}M`;case 'en-zh_CN':  return `${getSubStrNum(s, mUnit, 0, truncate)}M`;case 'zh-zh':  return `${getSubStrNum(s, yiUnit, 1, truncate)}\u5104`;case 'zh_CN-zh_CN':  return `${getSubStrNum(s, yiUnit, 1, truncate)}\u4ebf`;default:  return formatNumberStandard(s, 1);  }}if (s >= 1000000000 || s <= -1000000000) {  switch (locale) {case 'en-zh':  return `${getSubStrNum(s, bUnit, 1, truncate)}B`;case 'en-zh_CN':  return `${getSubStrNum(s, bUnit, 1, truncate)}B`;case 'zh-zh':  return `${getSubStrNum(s, yiUnit, 0, truncate)}\u5104`;case 'zh_CN-zh_CN':  return `${getSubStrNum(s, yiUnit, 0, truncate)}\u4ebf`;default:  return formatNumberStandard(s, 1);  }}return formatNumberStandard(s, precision);  }
            },
            "inverse": false,
            "offset": 0,
            "splitNumber": 5,
            "minInterval": 0,
            "splitLine": {
                "show": false,
                "lineStyle": {
                    "show": true,
                    "width": 1,
                    "opacity": 1,
                    "curveness": 0,
                    "type": "solid"
                }
            }
        }
    ],
    "title": [
        {
            "padding": 5,
            "itemGap": 10
        }
    ],
    "visualMap": [
        {
            "show": false,
            "type": "piecewise",
            "min": 0,
            "max": 100,
            "inRange": {
                "color": [
                    "#50a3ba",
                    "#eac763",
                    "#d94e5d"
                ]
            },
            "calculable": true,
            "inverse": false,
            "splitNumber": 5,
            "dimension": 0,
            "seriesIndex": 0,
            "orient": "vertical",
            "showLabel": true,
            "itemWidth": 20,
            "itemHeight": 14,
            "borderWidth": 0,
            "pieces": [
                {
                    "min": 0,
                    "max": 5,
                    "color": "red"
                },
                {
                    "min": 6,
                    "max": 7,
                    "color": "red"
                },
                {
                    "min": 5,
                    "max": 6,
                    "color": "blue"
                },
                {
                    "min": 7,
                    "max": 3,
                    "color": "blue"
                }
            ]
        }
    ]
};
        chart_769999bc905c4e638c19691647916950.setOption(option_769999bc905c4e638c19691647916950);
    </script>
</body>
</html>

报错信息

Traceback (most recent call last):
  File "/Users/xxxxxx/PycharmProjects/pythonProject1/chart.py", line 253, in <module>
    make_snapshot(snapshot,line_chart().render(),"demo.gif",pixel_ratio=1)
  File "/Users/xxxxxx/PycharmProjects/pythonProject1/venv/lib/python3.9/site-packages/pyecharts/render/snapshot.py", line 45, in make_snapshot
    raise OSError(content_array)
OSError: ["TypeError: null is not an object (evaluating 't.getAttribute')\n\n  https://assets.pyecharts.org/assets/echarts.min.js:19\n  https://assets.pyecharts.org/assets/echarts.min.js:19 in mf\n  :1\nnull\n"]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions