我想在 d3.json 的帮助下从 primefaces 返回一个 JSON 到 d3,但它会抛出错误。
我的primefaces bean,
@ManagedBean
@SessionScoped
public class JsonBean implements Serializable {
private static final long serialVersionUID = 1L;
JsonExample jse=new JsonExample();
public void prepareChartDate() {
RequestContext reqCtx = RequestContext.getCurrentInstance();
reqCtx.addCallbackParam("chartData",jse.createJson());
}
}
jse.createJson() 将 json 作为
{"A":10,"B":20,"C":30,"weekdays":["Sun","Mon","Tues"]}
我在 .xhtml 文件中调用的 d3js 代码是
<script src="http://d3js.org/d3.v3.js"></script>
<script>
var data;
d3.json("#{jsonBean.prepareChartDate()}",function(error, json) {
if (error) return console.warn(error);
data = json;
console.log(data);
//console.log("hello");
});
</script>
当我在控制台中打印时,它在萤火虫中给出错误。