I need help solving something that neither ChatGPT nor BlackBox were able to figure out. I need to make that blue button disappear along with its label "My first Dataset". I tried to find the answer by reading almost everything on the official link https://www.primefaces.org/showcase-v8/ui/chartjs/line.xhtml, but unfortunately, I couldn't find the solution. Please save my soul!
Here is the method on my MB:
public void createComparativoDiaAnteriorLinhas() {
this.lineModel = new LineChartModel();
ChartData data = new ChartData();
LineChartDataSet dataSet = new LineChartDataSet();
List<Number> values = new ArrayList<>();
values.add(65);
values.add(59);
values.add(80);
values.add(81);
values.add(56);
values.add(55);
values.add(40);
dataSet.setData(values);
dataSet.setFill(false);
dataSet.setLabel("My First Dataset");
dataSet.setBorderColor("rgb(75, 192, 192)");
dataSet.setLineTension(0.1);
data.addChartDataSet(dataSet);
List<String> labels = new ArrayList<>();
labels.add("January");
labels.add("February");
labels.add("March");
labels.add("April");
labels.add("May");
labels.add("June");
labels.add("July");
data.setLabels(labels);
//Options
LineChartOptions options = new LineChartOptions();
Title title = new Title();
title.setDisplay(true);
title.setText("Line Chart");
options.setTitle(title);
lineModel.setOptions(options);
lineModel.setData(data);
}
Bellow is the xhtml code:
<p:lineChart model="#{chartJsView.lineModel}"
style="width: 100%;
height: 500px;"/>
That "blue button" and its label is the chart legend; you have to disable that legend. Using the code in these docs, somewhere after you have constructed a LineChartOptions
instance that you'll be using to set options of the model, i.e., after
LineChartOptions options = new LineChartOptions();
and before
lineModel.setOptions(options);
you have to insert this:
Legend legend = new Legend();
legend.setDisplay(false);
options.setLegend(legend);