How to display No Data Available Message in highcharts

假装没事ソ 提交于 2019-12-21 03:36:27

问题


Can we display a message using highcharts, when the data set does not return any data? For example : "No Data Available"


回答1:


This has been added per the uservoice entry.




回答2:


It is now supported in Highcharts since v3.0.8

You need to load the no-data module and then, you can specify a custom message through the lang.noData option:

Highcharts.setOptions({lang: {noData: "Your custom message"}});



回答3:


I used a little workaround to solve this problem. Basically I'm overlaying a div containing the message "No Data to Display".

.noChartData {
     display: hidden;         
     position: absolute;
     z-index: 99;
     font-family: Arial, Helvetica, sans-serif;
     font-size: 16px;
     font-weight: normal;
     color: #CCC;
}

<div class="noChartData">No Data to Display</div>

When the page loads I'm using JQuery to find the position of the chart then offsetting the "No Data" div and revealing it accordingly.

var chartPosition = $("#myChart").position();
$(".noChartData").css("left", chartPosition.left + 400);
$(".noChartData").css("top", chartPosition.top + 150);

You'll need to vary the offsets accordingly depending on the size of your chart. I am using an AJAX call to pull in the series and category data so I know just before I bind the chart whether or not to reveal the floating "No Data" div.




回答4:


A very simple example:

Highcharts.setOptions({lang: {noData: "Your custom message"}})
var chart = Highcharts.chart('container', {
    series: [{
        data: []
    }]
});
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/no-data-to-display.js"></script>

<div id="container" style="height: 250px"></div>

Hope this helps someone



来源:https://stackoverflow.com/questions/19008625/how-to-display-no-data-available-message-in-highcharts

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!