繁体   English   中英

添加JavaScript代码以从文件中为python django仪表板获取数据

[英]Adding javascript code to pick up data from file for python django dashboard

尝试使用我需要添加到仪表板的数据来拾取数据文件。 每当我添加此代码时,整个JavaScript文件都会杀死我的django服务器。 数据文件存在。 我试图在函数外添加此代码,并在函数内尝试并获得相同的结果。

/* global $, Dashboard */

var dashboard = new Dashboard();

dashboard.addWidget('clock_widget', 'Clock');

dashboard.addWidget('current_valuation_widget', 'Number', {
    var request = new XMLHttpRequest();
    request.open('GET', 'text.txt');
    request.onreadystatechange = function() {
    if (request.readyState === 4) {
        var textfileContent = request.responseText;
        // continue your program flow here
    }
}
request.send();

    getData: function () {
        $.extend(this.scope, {
            title: 'Current Valuation',
            moreInfo: 'In billions',
            updatedAt: 'Last updated at 14:10',
            detail: '64%',
            value: '$35',
            icon: 'fa fa-arrow-up',
            dept: 'POIT'
        });
    }
});

dashboard.addWidget('buzzwords_widget', 'List', {
    getData: function () {
        $.extend(this.scope, {
            title: 'Buzzwords',
            moreInfo: '# of times said around the office',
            updatedAt: 'Last updated at 18:58',
            data: [{label: 'Exit strategy', value: 24},
                   {label: 'Web 2.0', value: 12},
                   {label: 'Turn-key', value: 2},
                   {label: 'Enterprise', value: 12},
                   {label: 'Pivoting', value: 3},
                   {label: 'Leverage', value: 10},
                   {label: 'Streamlininess', value: 4},
                   {label: 'Paradigm shift', value: 6},
                   {label: 'Synergy', value: 7}]
        });
    }
});

dashboard.addWidget('convergence_widget', 'Graph', {
    getData: function () {
        $.extend(this.scope, {
            title: 'Convergence',
            value: '41',
            moreInfo: '',
            data: [
                    { x: 0, y: 40 },
                    { x: 1, y: 49 },
                    { x: 2, y: 38 },
                    { x: 3, y: 30 },
                    { x: 4, y: 32 }
                ]
            });
    }
});

dashboard.addWidget('completion_widget', 'Knob', {
    getData: function () {
        $.extend(this.scope, {
            title: 'Completion',
            updatedAt: 'Last updated at 14:10',
            detail: 'today 10',
            value: '35',
            data: {
                angleArc: 250,
                angleOffset: -125,
                displayInput: true,
                displayPrevious: true,
                step: 1,
                min: 1,
                max: 99,
                readOnly: true,
                format: function(value) { return value + '%'; }
            }
        });
    }
});

仪表板具有内置的API。我将使用curl进行推送。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM