echarts在没数据时,在容器中加载暂无数据,然后再切换有数据的图表时,已然在容器中显示暂无数据,不会刷新图表。
jQuery.getReqInterface("I005", { reportId: "RPT13028", token: token, branch_no: branch_no, stat_month: stat_month}, function(data)
{
var html = "";
var month_list = [];
var data_list = [];
if(data.list.length>0){
jQuery.each(data.list,function(n, value){
var month_list_stat = value.STAT_MONTH;
month_list[n] = month_list_stat.substr(4,2);
data_list[n] = value.LOSS_SERV;
});
loadchart3(month_list,data_list);
}
else{
jQuery("#chart3").html('<div id="chart3-nodata" style="text-align: center;font-weight: bold;line-height: 140px">暂无数据</div>')
}
});
echart的代码为
function loadchart3(month_list,data_list)
{
var myChart3 = echarts.init(document.getElementById('chart3'));
var option3 = {
noDataLoadingOption:
{
text: '暂无数据',
effect: 'bubble',
effectOption:
{
effect:
{
n: 0
}
}
},
grid:
{
top: '20%',
left: '3%',
right: '2%',
bottom: '10%',
containLabel: true
},
xAxis:
{
data: month_list,
splitLine:
{
show: false
}
},
yAxis:
{
splitLine:
{
show: false
},
type: 'value',
min: 0,
precision: 2
},
series: [
{
type: 'bar',
areaStyle: { normal: { color: '#2a8efc' } },
//data: marketing_rate_list,
data: data_list,
barWidth: 18,
label: {
normal: {
show: true,
position: 'top'
}
},
itemStyle:
{
normal:
{
color: '#2a8efc'
}
}
}]
};
myChart3.setOption(option3);
请问下应该怎么处理。
谢邀,你尝试一下当判断为有数据时,将
"div#chart3"
中的内容先清空再执行echarts
,另外,将echarts
实例提取出来,不要每次都创建。