javascript - HighCharts getJson - 无法显示

标签 javascript highcharts

我的服务器返回的 Json

{
    "data": [{
        "name": "name",
        "data": ["[Date.UTC(2017, 01, 25), 89]",
                 "[Date.UTC(2017, 01, 26), 99]",
                 "[Date.UTC(2017, 02, 02), 106]",
                 "[Date.UTC(2017, 02, 04), 102]",
                 "[Date.UTC(2017, 02, 07), 110]",
                 "[Date.UTC(2017, 10, 31), 155]"]
    }]
}

我使用的代码仅来 self 生成的数据(上图) https://www.highcharts.com/demo/spline-irregular-time

我的Javascript代码

Please Remove one T from bit ly
    $.getJSON('http://bitt.ly/2zpoZqT', function (csv) {
        console.log(csv['data']);
        Highcharts.chart('container', {
        chart: {
            type: 'spline'
        },
        title: {
            text: 'Keyword Tracking'
        },
        subtitle: {
            text: 'Top 20 Keywords'
        },
        xAxis: {
            type: 'datetime',
            dateTimeLabelFormats: { // don't display the dummy year
                month: '%e. %b',
                year: '%b'
            },
            title: {
                text: 'Date'
            }
        },
        yAxis: {
            title: {
                text: 'Snow depth (m)'
            },
            min: 0
        },
        tooltip: {
            headerFormat: '<b>{series.name}</b><br>',
            pointFormat: '{point.x:%e. %b}: {point.y:.2f} m'
        },

        plotOptions: {
            spline: {
                marker: {
                    enabled: true
                }
            }
        },

        series: csv['data']
    });

    });

最佳答案

只需将良好的属性 series 添加到成功调用 $.getJSON 中的对象 json 返回中,就像您所做的那样。但本例根据脚本需要创建一个属性 series ,并将 data 的值影响series >删除数据你就完成了。

    $.getJSON('http://bitt.ly/2zpoZqT', function (csv) {
        console.log(csv['data']);
        csv.series = csv.data;//new attribute series affected to data
        delete csv.data; //delete data to have the good object
        Highcharts.chart('container', {
        chart: {
            type: 'spline'
        },
        title: {
            text: 'Keyword Tracking'
        },
        subtitle: {
            text: 'Top 20 Keywords'
        },
        xAxis: {
            type: 'datetime',
            dateTimeLabelFormats: { // don't display the dummy year
                month: '%e. %b',
                year: '%b'
            },
            title: {
                text: 'Date'
            }
        },
        yAxis: {
            title: {
                text: 'Snow depth (m)'
            },
            min: 0
        },
        tooltip: {
            headerFormat: '<b>{series.name}</b><br>',
            pointFormat: '{point.x:%e. %b}: {point.y:.2f} m'
        },

        plotOptions: {
            spline: {
                marker: {
                    enabled: true
                }
            }
        },

        series: csv['data']
    });

    });

关于javascript - HighCharts getJson - 无法显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47057730/

相关文章:

javascript 在 10 分钟内监听 http post 请求,如果没有则取消它

javascript - 如何将 Django 中的数组传递给模板并与 JavaScript 一起使用

javascript - tablesorter 小部件过滤任何匹配项。如何只搜索所有列(删除对单个列的搜索)

javascript - 将 AngularJs javascript 文件包含到 Angular cli 中

javascript - 仪表车速表

javascript - 在 Highcharts 中,如何为多金字塔图表中的每个金字塔设置标题

javascript - 这是一些跨域问题吗?

json 日期格式转换为 Highcharts 日期格式

javascript - 如何将 django 上下文变量传递到 javascript 中?

Javascript:TinyMCE + Highcharts