javascript - 如何显示在 Highcharts 中找不到数据

标签 javascript highcharts

在highcharts中,如果json值中没有找到数据,我想显示一条错误消息。

我使用了这段代码:

if(options.series[0].data.length == 0) {
    alert('nodatafound');
} else {
    var chart = new Highcharts.Chart(options);
}

出现此错误:

TypeError: options.series[0].data is undefined

来自 JSON 的数据:

{
    "chart": {
        "renderTo": "container2",
        "type": "column",
        "marginRight": 10,
        "marginBottom‌": 125
    },
    "title": {
        "text": "",
        "x": -20
    },
    "exporting": {
        "enabled": false
    },
    "credits": {
        "enab‌led": false
    },
    "subtitle": {
        "text": "",
        "x": -20
    },
    "xAxis": {
        "labels": {
            "rotation": -90,
            "sty‌le": {
                "fontSize": "10px"
            }
        }
    },
    "yAxis": {
        "title": {
            "text": ""
        },
        "plotLines": [{
            "width": 1,
            "c‌olor": "#808080"
        }]
    },
    "tooltip": {
        "shared": true
    },
    "legend": {
        "align": "right",
        "verticalA‌lign": "top",
        "x": 0,
        "y": 20,
        "borderWidth": 0
    },
    "plotOptions": {
        "column": {
            "stacking": "no‌rmal",
            "dataLabels": {
                "enabled": false,
                "color": "white"
            }
        }
    },
    "series": [{
        "name": "2015-16-Q1"
    }, {
        "name": "2015-16-Q2"
    }, {
        "name": "2015-16-Q3"
    }, {
        "na‌me": "2015-16-Q4"
    }]
}

最佳答案

您可以使用no-data module这允许这样做。

引用:http://code.highcharts.com/modules/no-data-to-display.js

示例:http://jsfiddle.net/6o8o03fe/1/

关于javascript - 如何显示在 Highcharts 中找不到数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30707403/

相关文章:

Javascript 原型(prototype) - 在这种情况下有什么优势?

javascript - 如何将字符串值作为函数参数从html传递给javascript?

javascript - 使用 Highcharts.js 在 x Axis 上显示日期

highcharts - 无论间距限制如何,如何强制 highcharts 显示每个 x 轴标签?

javascript - Highcharts :Uncaught TypeError: $(. ..).highcharts 不是函数

javascript - React-highcharts 滚动条功能不起作用

Javascript DatePicker 无法运行

javascript - 如何在 JavaScript 中验证此正则表达式?

javascript - 如何在 Phonegap 中存储多维数组

javascript - 如何动态加载highcharts