echarts icon indicating copy to clipboard operation
echarts copied to clipboard

How to display "No Data" message on echart

Open coskuntekin opened this issue 9 years ago • 11 comments

How we can display No Data message on echart?

coskuntekin avatar May 25 '17 01:05 coskuntekin

You need to show no data message with HTML by yourself.

pissang avatar May 31 '17 03:05 pissang

@pissang here is a solution by title.

 title: {
        show: false,
        textStyle:{
          color:'#bcbcbc'
        },
        text: '没有数据',
        left: 'center',
        top: 'center'
      }

coskuntekin avatar Jun 01 '17 04:06 coskuntekin

@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 avatar Jun 24 '17 17:06 rachits21

@rachits21 sorry i didn't test on PIE chart.

coskuntekin avatar Jun 26 '17 07:06 coskuntekin

@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 avatar Sep 09 '17 04:09 tongxuehello

@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.

coskuntekin avatar Sep 11 '17 07:09 coskuntekin

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

sebuelias avatar Aug 28 '18 05:08 sebuelias

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

swuecho avatar May 29 '19 05:05 swuecho

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"

larrykkk avatar Sep 25 '19 03:09 larrykkk

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(...);
});

MiroslavMikus avatar Nov 18 '21 23:11 MiroslavMikus

Another solution is to use an overlay

graphic: {
 type: 'text',
 left: 'center',
 top: 'middle',
 style: { text: "No data available" }
}

teuf22 avatar May 17 '22 13:05 teuf22