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

custom dashlet echarts #117

Open
annProg opened this issue Oct 14, 2020 · 1 comment
Open

custom dashlet echarts #117

annProg opened this issue Oct 14, 2020 · 1 comment

Comments

@annProg
Copy link
Collaborator

annProg commented Oct 14, 2020

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
    <div id="main" style="width: 600px;height:400px;"></div>
    <!-- 引入 ECharts 文件 -->
    <script type="text/javascript">
        $.getScript("https://cdn.bootcdn.net/ajax/libs/echarts/5.0.0-alpha.2/echarts.common.min.js");
    </script>
    <script type="text/javascript">
    function EchartDraw() {
        // 基于准备好的dom,初始化echarts实例
        var myChart = echarts.init(document.getElementById('main'));

        // 指定图表的配置项和数据
        var option = {
            title: {
                text: 'ECharts 入门示例'
            },
            tooltip: {},
            legend: {
                data:['销量']
            },
            xAxis: {
                data: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"]
            },
            yAxis: {},
            series: [{
                name: '销量',
                type: 'bar',
                data: [5, 20, 36, 10, 10, 20]
            }]
        };

        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
    }
    
    // 如何每500ms判断一次?
    // setTimeout 似乎只能执行一次
    for(var i=0;i<5;i++) {
        if(typeof echarts == "undefined") {
            setTimeout("EchartDraw()", 5000);
            continue;
            
        } else {
            EchartDraw();
            break;
        }
    }
    </script>
</body>
</html>
@annProg
Copy link
Collaborator Author

annProg commented Oct 15, 2020

直接在 add_script 里手写 $.getScript 回调即可,不要用 add_linked_script

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

1 participant