PrimeFaces ChartJS 无法解决 [英] PrimeFaces ChartJS can not be resolved

查看:35
本文介绍了PrimeFaces ChartJS 无法解决的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 PrimeFaces 6.0,我想在我的 JSF 项目上测试 ChartJS.问题是我收到此错误:

I am using PrimeFaces 6.0 and I wanted to test ChartJS on my JSF project. The problem is that I am getting this error:

导入 org.primefaces.model.charts 无法解析

The import org.primefaces.model.charts Cannot be resolved

我尝试了所有可能的解决方案,例如清理、刷新和更新项目.我还尝试了最新的 PrimeFaces 版本 5/6/6.1/6.2在我尝试使用 PrimeFaces ChartJS 时,其他主题中给出的解决方案与 PrimeFaces Chart 等其他导入相关.这是我取自的代码:https://www.primefaces.org/showcase/ui/chartjs/donut.xhtml

I tried all the possible solutions such as cleaning, refreshing and updating the project. I also tried with the latest PrimeFaces versions 5/6/6.1/6.2 The solutions given in other topics are related to other imports like PrimeFaces Chart while I am trying to use the PrimeFaces ChartJS. Here is the code that I took from: https://www.primefaces.org/showcase/ui/chartjs/donut.xhtml

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import org.primefaces.model.charts.ChartData;
import org.primefaces.model.charts.donut.DonutChartDataSet;
import org.primefaces.model.charts.donut.DonutChartModel;

@ManagedBean
public class ChartJsView implements Serializable {

    private DonutChartModel donutModel;

    @PostConstruct
    public void init() {
        createDonutModel();
    }

    public void createDonutModel() {
        donutModel = new DonutChartModel();
        ChartData data = new ChartData();

        DonutChartDataSet dataSet = new DonutChartDataSet();
        List<Number> values = new ArrayList<>();
        values.add(300);
        values.add(50);
        values.add(100);
        dataSet.setData(values);

        List<String> bgColors = new ArrayList<>();
        bgColors.add("rgb(255, 99, 132)");
        bgColors.add("rgb(54, 162, 235)");
        bgColors.add("rgb(255, 205, 86)");
        dataSet.setBackgroundColor(bgColors);

        data.addChartDataSet(dataSet);
        List<String> labels = new ArrayList<>();
        labels.add("Red");
        labels.add("Blue");
        labels.add("Yellow");
        data.setLabels(labels);

        donutModel.setData(data);
    }

    public DonutChartModel getDonutModel() {
        return donutModel;
    }

    public void setDonutModel(DonutChartModel donutModel) {
        this.donutModel = donutModel;
    }
}

推荐答案

ChartJs 是 PrimeFaces 6.2.9 Elite 版本中的全新内容.

ChartJs is brand new in PrimeFaces 6.2.9 Elite version.

因此,如果您想使用这些新的 ChartJ,您要么必须成为 Elite 订阅者,要么自己从 Github 的源代码中构建 6.3-SNAPSHOT.

So you either have to be an Elite subscriber or build 6.3-SNAPSHOT yourself from the source in Github if you want to use these new ChartJs.

这篇关于PrimeFaces ChartJS 无法解决的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆