PieChart

image not found image not found image not found

Optimal data structure (database)

Category

Value

Bverages

393

Condiments

507

Confections

386

Optimal object structure (Java)

public class PieChartObject {
    private String category;
    private Integer value;

    public String getCategory() {
        return this.category;
    }

    public void setCategory(final String category) {
        this.category = category;
    }

    public Integer getValue() {
        return this.value;
    }

    public void setValue(final Integer value) {
        this.value = value;
    }
}

Example: Filling the data

final ChartModel model = ChartModel.New()
    .addColumn(Column.New(Type.STRING))
    .addColumn(Column.New(Type.NUMBER));

model.addRow("Katze", 50);
model.addRow("Hund", 25);
model.addRow("Schlange", 25);

this.pieChart.setModel(model);

or by looping from query method:

final ChartModel model = ChartModel.New()
    .addColumn(Column.New(Type.STRING))
    .addColumn(Column.New(Type.NUMBER));

new ProductDAO().getProductsByCategoryForChart().forEach(p -> {
    model.addRow(p.getCategory().getCategoryname(), (int)p.getAmount());
});

chart.setModel(model);

API and methods:

Configuration "XdevPieChartConfig" general:

Properties

PieHole

If the value is between 0 and 1, a donut diagram is displayed. The hole has a radius equal to number times the radius of the diagram.

pieChart.setPieHole(0.5);

PieStartAngle

The angle in degrees by which the graph should be rotated. The default value "0" aligns the left edge of the first slice directly upwards.

pieChart.setPieStartAngle(60);

PieSliceBorderColor

The color of the slice borders. Only applicable if the diagram is two-dimensional.

pieChart.setPieSliceBorderColor("red");

PieSliceText

The content of the text that will be displayed on the slice. Can be one of the following values:

  • 'percentage' - The percentage of the slice size to the total size.

  • 'value' - The quantitative value of the slice.

  • label' - the name of the slice.

  • 'none' - no text will be displayed

pieChart.setPieSliceText(PieSliceText.PERCENTAGE);

SliceVisibilityThreshold

The partial value of the pie below which a slice is not displayed individually. All slices that have not exceeded this threshold are combined into a single "Other" slice whose size is equal to the sum of all its sizes. By default, all slices smaller than half a degree are not displayed individually.

pieChart.setSliceVisibilityThreshold(25);

Is3D

If true, a three-dimensional diagram is displayed.

pieChart.setIs3D(true);