2016-06-10 34 views
1

我最初制作了一个包含数据的图表,但是如果数据在载入函数的图表中不可用,它不会显示没有可用数据的字符串。如何在c3 JS图表的加载函数中显示没有数据

var chart = c3.generate({ 
 
bindto: '#chart1', 
 
data: { 
 
     columns: [ 
 
      ['data1', -30, 200, 200, 400, -150, 250], 
 
      ['data2', 130, 100, -100, 200, -150, 50] 
 
     ], 
 
     type: 'bar', 
 
     groups: [ 
 
      ['data1', 'data2'] 
 
     ], 
 
     empty: { label: { text: "No Data Available" } } 
 
    }, 
 
    grid: { 
 
     y: { 
 
      lines: [{value:0}] 
 
     } 
 
    } 
 
}); 
 

 

 
setTimeout(function() { 
 

 
    chart.load({ 
 
     columns: [ 
 
     
 
     
 
     ], 
 
     empty: { label: { text: "No Data Available" } } 
 
    }); 
 
    chart.flush(); 
 
}, 1500);
<link href="https://rawgit.com/masayuki0812/c3/master/c3.css" rel="stylesheet"/> 
 
<script src="https://rawgit.com/masayuki0812/c3/master/c3.js"></script> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script> 
 
<div id="chart1"></div>

如何显示无负载功能提供数据?

回答

1

对于加载新数据,你需要通过自己的ID,以卸载旧的数据:

setTimeout(function() { 
    chart.load({ 
    columns: [], 
    unload: ['data1', 'data2']//here data1, data2 are your old data ids 
    }); 

chart.flush(); 
}, 1500); 

工作代码here

+0

工作就像一个魅力。谢谢 :) – Raichu

相关问题