【发布时间】:2014-09-15 18:56:29
【问题描述】:
我想在我的 jsf 项目中使用 jquery 图表来做一些统计,如何在我的 jquery 函数中调用 Java 方法(来自 managedbesn)? 这是我的 jquery 函数来显示条形图
var randomScalingFactor = function(){ return Math.round(Math.random()*100)};
var barChartData = {
labels : ["January","February","March","April","May","June","July"],
datasets : [
{
fillColor : "rgba(220,220,220,0.5)",
strokeColor : "rgba(220,220,220,0.8)",
highlightFill: "rgba(220,220,220,0.75)",
highlightStroke: "rgba(220,220,220,1)",
data : [randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor()]
},
{
fillColor : "rgba(151,187,205,0.5)",
strokeColor : "rgba(151,187,205,0.8)",
highlightFill : "rgba(151,187,205,0.75)",
highlightStroke : "rgba(151,187,205,1)",
data : [randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor()]
}
]
}
window.onload = function(){
var ctx = document.getElementById("canvas").getContext("2d");
window.myBar = new Chart(ctx).Bar(barChartData, {
responsive : true
});
}
我想用java方法调用的数据填写字段标签(标签:[“一月”,“二月”,“三月”,“四月”,“五月”,“六月”,“七月”])例如:
public list getmonths(){--------code-------}
【问题讨论】:
-
发布您尝试过的内容,以便我们了解您的想法。
-
当然它可能包括 ajax
-
但我不明白这样做有什么问题。 @ArunPJohny
-
很多初学者都没有意识到 JSF 在这类问题的上下文中仅仅是一个 HTML/CSS/JS 代码生成器。因此,您所要做的就是编写 JSF 代码,使其准确生成所需的 JS 输出。例如。
<script>var foo = '#{bean.foo}';</script>。你知道吗,比尔?如果是这样,那么请重新构建问题以提出更具体的问题并详细说明为什么这种方法不合适。 -
好方法 BalusC thxs :)