【问题标题】:Unable to load Json data in MG data tableMG数据表无法加载Json数据
【发布时间】:2015-07-27 05:55:56
【问题描述】:

我是 D3.js 的新手。 我创建了一个脚本,但我无法将任何 json 数据加载到我的表中。

d3.json('C:\Software\Data\dirk\development\D3_TestLab\data\StatusTabel.json', function (data) {

    var table_data = data

    var table1 = MG.data_table({
        data: table_data,
        //title: '',
        //description: 'A table has many of the same properties as any other data graphic.',
        show_tooltips: true
    })

        .target('#div1')

        .number({ accessor: 'BU', label: 'BU', width: 120, font_size: 14, layout: 'center' })
        .number({ accessor: 'Lines', label: '# Lines', width: 190, font_size: 14, layout: 'center' })
      //.number({accessor: 'Errors', label: 'Errors', width: 170, font_size: 14, color: function(d){ return d > 0 ? '#f70101' : 'auto'; })
        .number({ accessor: 'Errors', label: 'Errors', width: 190, font_size: 14, color: 'red', allign: 'center' })
        .number({ accessor: 'Shift', label: 'Shift', width: 270, font_size: 14 })

        .display();
})

【问题讨论】:

    标签: javascript html json d3.js


    【解决方案1】:

    我没有检查你的逻辑,但我可以在这里建议的几点是,

    1) 尝试将 url 更改为 json 文件: 'C:\Software\Data\dirk\development\D3_TestLab\data\StatusTabel.json' 到: 'file:///C:/Software/Data/dirk/development/D3_TestLab/data/StatusTabel.json'

    2) 函数(数据)应该有另一个参数错误。即函数(错误,数据){ ... }

    希望这会有所帮助。

    【讨论】:

      【解决方案2】:

      如上所述,函数应该有两个参数function(error, data)。如果您甚至收到 JSON 文件,也可以进行调试,请尝试在读取 JSON 后立即添加console.log(JSON.stringify(data));。这样您就可以查看通话是否正常。

      【讨论】:

        猜你喜欢
        • 2014-04-05
        • 1970-01-01
        • 1970-01-01
        • 2019-10-23
        • 2017-01-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多