📜  Primefaces AreaChart

📅  最后修改于: 2021-01-08 04:41:57             🧑  作者: Mango

PrimeFace AreaChart

它是LineChart的自定义和高级版本,其中填充了系列。它用于以图形方式表示统计数据。 是在JSF应用程序中创建图表的通用组件。我们可以设置图表类型以指定pf图表的类型。

图表具有下表列出的各种属性。这些属性是通用属性,适用于所有类型的图表。

图表属性

Attribute Default value Type Description
id null String It is an unique identifier of the component.
rendered true Boolean It takes boolean value to specify the rendering of the component.
type null String It is used to specify type of the chart.
model null ChartModel It is used to set model object of data and settings.
style null String It is used to set inline style of the component.
widgetVar null String It is a name of the client side widget.
responsive false Boolean In responsive mode, chart is redrawn when
window is resized.

在下面的示例中,我们正在实现组件。本示例包含以下文件。

JSF文件

// area.xhtml





Area





ManagedBean

// Area.java

package com.javatpoint;
import javax.annotation.PostConstruct;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import org.primefaces.model.chart.Axis;
import org.primefaces.model.chart.AxisType;
import org.primefaces.model.chart.CategoryAxis;
import org.primefaces.model.chart.LineChartModel;
import org.primefaces.model.chart.LineChartSeries;
@ManagedBean
public class Area implements Serializable {
private LineChartModel drawArea;
@PostConstruct
public void init() {
createDrawArea();
}
public LineChartModel getDrawArea() {
return drawArea;
}
private void createDrawArea() {
drawArea = new LineChartModel();
LineChartSeries boys = new LineChartSeries();
boys.setFill(true);
boys.setLabel("Boys");
boys.set("2010", 140);
boys.set("2011", 120);
boys.set("2012", 64);
boys.set("2013", 170);
boys.set("2014", 45);
LineChartSeries girls = new LineChartSeries();
girls.setFill(true);
girls.setLabel("Girls");
girls.set("2010", 72);
girls.set("2011", 80);
girls.set("2012", 130);
girls.set("2013", 110);
girls.set("2014", 140);
drawArea.addSeries(boys);
drawArea.addSeries(girls);
drawArea.setTitle("Area Chart");
drawArea.setLegendPosition("ne");
drawArea.setStacked(true);
drawArea.setShowPointLabels(true);
Axis xAxis = new CategoryAxis("Years");
drawArea.getAxes().put(AxisType.X, xAxis);
Axis yAxis = drawArea.getAxis(AxisType.Y);
yAxis.setLabel("Births");
yAxis.setMin(0);
yAxis.setMax(300);
}
}

输出: