How to display "No Data" message on echart
How we can display No Data message on echart?
You need to show no data message with HTML by yourself.
@pissang here is a solution by title.
title: {
show: false,
textStyle:{
color:'#bcbcbc'
},
text: '没有数据',
left: 'center',
top: 'center'
}
@coskuntekin Its Not Working. I did this`agePieData = [];
var option1 = {
title: {
show: true,
textStyle:{
color:'#bcbcbc'
},
text: 'No Data',
left: 'center',
top: 'center'
},
series: [{
name: 'Age group',
type: 'pie',
radius: '55%',
center: ['50%', '60%'],
data: agePieData
}]
}
myAgePieChart.setOption(option1);`
@rachits21 sorry i didn't test on PIE chart.
@coskuntekin I solved this problem by this way: clear echarts instance first, then setOption with custom title option (without series data and hide axis line). By the way, you can add background to the option.
var showChartInfo = function (divId, infoStr) {
var msgOption = {
title: {
show: true,
textStyle:{
color:'grey',
fontSize:20
},
text: infoStr,
left: 'center',
top: 'center'
},
xAxis: {
show: false
},
yAxis: {
show: false
},
series: []
};
initChart(divId).clear() //initChart(divId): get echarts instance, you can get it by using other method
initChart(divId).hideLoading()
initChart(divId).setOption(msgOption)
};
@tongxuehello looks like nice. So it's mean you setting options two times. One is for have no data options, another is series has data. I like it. Thank you for sharing.
Hi, how do you know set when there is data and where there is no data? How do you set options? As in, how do you detect when the series is there or not. @coskuntekin @tongxuehello
anther approach is to use @tanzhongyibidu 's msgOption as default option. overwrite it when you have data. Obviously, if no data is available, the chart display the default plot, which is $infoStr message
use the data.length to control Echart option
title: {
show: answerCountArr.length === 0,
textStyle: {
color: "grey",
fontSize: 20
},
text: "No data",
left: "center",
top: "center"
},
xAxis: {
show: answerCountArr.length,
//...
},
yAxis: {
show: answerCountArr.length,
//...
},
if data.length is false then chart will only show "No data"
Looks like I'm pretty late in this discussion.
BTW you can manage it by yourself and show some nice animation. Docu here. Example:
myChart.showLoading();
$.get('data.json').done(function (data) {
myChart.hideLoading();
myChart.setOption(...);
});
Another solution is to use an overlay
graphic: {
type: 'text',
left: 'center',
top: 'middle',
style: { text: "No data available" }
}