0

我在 JSF 2.1 中使用 Raphael 图表。我正在尝试绘制一个折线图,它接受 x 轴的输入是一个数组数组,y 轴也是如此。我的 x 轴应该包含时间戳(xhtml 中的 xvals),y 轴应该包含 avgVal(xhtml 中的 avgbpsvals)。如何在 javascript 中访问 TBean 实例变量,如 dt、avgVal?ui:repeat 只给我结果bean。

    Class InputBean{
    private List<List<TBean>> results;
    private List<TBean> result;
private String resultJSON;
    //getters and setters
private String getResultJSON(){
Gson gson = new Gson();
return gson.toJson(results);
}
    }

Class TBean{
private Timestamp dt;
private Long avgVal;
//getters and setters
}

在 sample.xhtml

    <?xml version='1.0' encoding='UTF-8' ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:ui="http://java.sun.com/jsf/facelets"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:p="http://primefaces.org/ui">
    <f:view contentType="text/html">
    <h:head>
    <script type="text/javascript" src="/resources/js/raphael.js"></script>
            <script type="text/javascript" src="/resources/js/g.raphael.js"></script>
            <script type="text/javascript" src="/resources/js/g.line.js"></script>
            <script type="text/javascript" charset="utf-8">
    window.onload = function() {
                    var r = Raphael("holder", 1000, 1000);
    var results = #{inputTablePlot.resultJSON};
 for(var i=0; i &lt; results.length; i++)
                {
                    for(var j=0; j &lt; results[i].length; j++)
                    {
                        alert("j : " + j);
                        alert("value: " + results[i][j].avgVal);
                    }
                }
                    var lines = r.linechart(40, 30, 900, 900, xvals,
                            avgbpsvals, {
                                smooth : true,
                                symbol : 'circle',
                                axis : "0 0 1 1"
                            });
                    };

    </script>
    </h:head>
    <h:body>
    <h:panelGroup id="holder" layout="block"></h:panelGroup>
    </h:body>
    </f:view>
    </html>
4

0 回答 0