0

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;
    }
}
Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
Romelou Striga
  • 96
  • 2
  • 10
  • 1
    Possible duplicate of [Eclipse error: "The import XXX cannot be resolved"](https://stackoverflow.com/questions/4322893/eclipse-error-the-import-xxx-cannot-be-resolved) – MarsAtomic Sep 14 '18 at 00:13
  • thanks for your response but I already tried Cleaning the project, refreshing and updating it but still the same problem. – Romelou Striga Sep 14 '18 at 01:12
  • 3
    Please don't use all capitals in sentences or titles. It is like shouting – Kukeltje Sep 14 '18 at 07:59

1 Answers1

3

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.

Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
Melloware
  • 10,435
  • 2
  • 32
  • 62