如何显示高图中未找到的数据

How to display no data found in highcharts

本文关键字:数据 高图中 何显示 显示      更新时间:2023-09-26

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

我使用了以下代码:

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

这个错误出现:

TypeError: options.series[0]。数据未定义

数据来自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模块。

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

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