Romelou Striga
Romelou Striga

Reputation: 96

PrimeFaces ChartJS can not be resolved

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:

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

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;
    }
}

Upvotes: 0

Views: 3565

Answers (1)

Melloware
Melloware

Reputation: 12019

ChartJs is brand new in PrimeFaces 6.2.9 Elite version.

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.

Upvotes: 3

Related Questions