GemPieChart
A pie chart, also called circle chart, looks like a circle, which is divided into slices to visualize information. Different categories of data can be indicated by different colors. It is helpful to observe the numerical proportion of data. For example, it can be used to show the market share of competing products, or the distribution of a household budget across expense categories.
Usage Example
/* (c) https://github.com/MontiCore/monticore */
package example_charts;
import Domain.Person;
import mc.fenix.charts.GemPieChart;
import common.ExamplePage;
page GemPieChartExample(List<Person> persons) {
@ExamplePage(
component = chart@GemPieChart(
data = null,
innerRadius = 10,
showConfig = true
),
basePath = "example_charts",
componentName = "GemPieChartExample"
);
}
TypeScript implementation:
/* (c) https://github.com/MontiCore/monticore */
package example_charts;
import domain.Person;
import mc.fenix.charts.gempiecharttypes.GemPieChartData;
import mc.fenix.charts.gempiecharttypes.GemPieChartDataBuilder;
import mc.fenix.charts.gempiecharttypes.GemPieChartEntry;
import umlp.jsweet.extension.annotation.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@Component
public class GemPieChartExample extends GemPieChartExampleTOP {
@Override
public GemPieChartData getChartData() {
if (this.getPersons() == null) {
return null;
}
List<GemPieChartEntry> dataEntries = new ArrayList<>();
dataEntries.add(new GemPieChartEntry(0, "People born before 1993", Optional.empty()));
dataEntries.add(new GemPieChartEntry(0, "People born in and after 1993", Optional.of("#57ab27")));
int group1 = 0;
int group2 = 0;
for (Person person : this.getPersons()) {
int personBirthday = person.getBirthday().getYear();
if (personBirthday < 1993) {
group1++;
}
else {
group2++;
}
}
dataEntries.get(0).setValue(group1);
dataEntries.get(1).setValue(group2);
return new GemPieChartDataBuilder().entries(dataEntries).build().get();
}
}
GUI Model
component GemPieChart(
GemPieChartData data,
Integer innerRadius,
boolean showConfig = false
)
| Name |
Type |
Description |
Default value |
data |
GemPieChartData |
The data (categories and their values) to be displayed in the chart. |
|
innerRadius |
Integer |
Radius of the inner hole in pixels; a value greater than 0 turns the pie chart into a donut chart. |
|
showConfig |
boolean |
Whether the chart's configuration panel is shown. |
false |
Types
GemPieChartTypes
package mc.fenix.charts;
import java.util.List;
import java.util.Optional;
<<pojoCD>>
classdiagram GemPieChartTypes {
public class GemPieChartData {
List<GemPieChartEntry> entries;
}
public class GemPieChartEntry {
Integer value;
String label;
Optional<String> backgroundColor;
}
}
GemPieChartData
| Name |
Type |
Description |
Default value |
entries |
List<GemPieChartEntry> |
|
|
GemPieChartEntry
| Name |
Type |
Description |
Default value |
value |
Integer |
|
|
label |
String |
|
|
backgroundColor |
Optional<String> |
|
|