javascript - 无法正确实现 Primefaces 图表

标签 javascript jsf jsf-2 charts primefaces

我想实现 Primefaces 图表。但我未能正确设置图表的图例:

enter image description here

这是我用来构建图表的代码:

<h:form>

    <p:barChart id="basic" value="#{DashboardController.categoryModel}" legendPosition="ne"  
                title="Accounts and Groups" min="0" max="#{DashboardController.chartMaxSize}" style="height:400px"
                shadow="true" barPadding="90" seriesColors="4D94FF, 1975FF, 005CE6, 0047B2" 
                yaxisLabel="Size"/>  
</h:form>

Java 代码:

private void createCategoryModel() throws SQLException, Exception
    {
        categoryModel = new CartesianChartModel();

        // Active Accounts

        ChartSeries chart = new ChartSeries();
        chart.setLabel("Active Accounts");

        chart.set("Active Accounts", countDBActiveAccounts());

        // Blocked Accounts

        chart.setLabel("Blocked Accounts");

        chart.set("Blocked Accounts", countDBBlockedAccounts());


        // Active Groups

        chart.setLabel("Active Groups");

        chart.set("Active Groups", countDBActiveGroups());


        // Blocked Groups

        chart.setLabel("Blocked Groups");

        chart.set("Blocked Groups", countDBBlockedGroups());

        categoryModel.addSeries(chart);



    }

你能帮我正确构建图表吗?

P.S 从 @Ravi 提出的代码中我得到了这个图表:

enter image description here

最佳答案

您应该像这样使用 ChartSeries 的单独实例

private void createCategoryModel() throws SQLException, Exception
{
    categoryModel = new CartesianChartModel();

    // Active Accounts

    ChartSeries actAcc = new ChartSeries();
    actAcc .setLabel("Active Accounts");

    actAcc.set("Active Accounts", countDBActiveAccounts());
    actAcc.set("Blocked Accounts", 0);
    actAcc.set("Active Groups", 0);
    actAcc.set("Blocked Groups", 0);

    // Blocked Accounts

    ChartSeries blocAcc = new ChartSeries();
    blocAcc.setLabel("Blocked Accounts");

    blocAcc.set("Active Accounts", 0);
    blocAcc.set("Blocked Accounts", countDBBlockedAccounts());
    blocAcc.set("Active Groups", 0);
    blocAcc.set("Blocked Groups", 0);


    // Active Groups

    ChartSeries actGrp = new ChartSeries();
    actGrp.setLabel("Active Groups");

    actGrp.set("Active Accounts", 0);
    actGrp.set("Blocked Accounts", 0);
    actGrp.set("Active Groups", countDBActiveGroups());
    actGrp.set("Blocked Groups", 0);


    // Blocked Groups

    ChartSeries blocGrp = new ChartSeries();
    blocGrp.setLabel("Blocked Groups");

    blocGrp.set("Active Accounts", 0);
    blocGrp.set("Blocked Accounts", 0);
    blocGrp.set("Active Groups", 0);
    blocGrp.set("Blocked Groups", countDBBlockedGroups());

    categoryModel.addSeries(actAcc );
    categoryModel.addSeries(blocAcc);
    categoryModel.addSeries(actGrp);
    categoryModel.addSeries(blocGrp);

}

关于javascript - 无法正确实现 Primefaces 图表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11748079/

相关文章:

javascript - 调用 JavaScript 方法失败

eclipse - 操作值与导航案例结果不匹配

javascript - 在 selectOneMenu 更改时在同一窗口中打开对话框

jsf-2 - 如何验证 selectOneMenu 的值?

ajax - :selectOneRadio not updating model in event "change" with p:ajax

php - 单击后禁用提交按钮并保持 POST/REDIRECT/GET 工作

Javascript如何提交表单?

javascript - 选择下拉方向

java - 从支持 bean 中关闭 JSP 弹出窗口?

java - 如何获取具有绝对路径的文件的 InputStream 并将其添加到 StreamedContent 对象以便在 p :fileDownload? 中使用它