-
Notifications
You must be signed in to change notification settings - Fork 298
GoogleCharts Loader API
Note: At the moment there are two Google Chart projects in wicketstuff with the following maven artefacts:
-
googlecharts
The first one, realized and based on the Image API, which was deprecated in 2012. See wiki page GoogleCharts for this.
-
gchart
The second and newer one, realized and based on the actual Loader API. gchart is the one this pages deals with.
The Google Charts Project allows creation of charts using the Google Chart API.
- gchart-parent
- gchart
- gchart-examples
The following example code reproduces the pie chart of the Quick Start.
The API does not try to hide the Google API, instead it gives just a way to build the charts in Java programming language as close as possible to the Google API and integrate it with Apache Wicket. So please read the documentation of the original API, if you are not familiar with Google charts.
<dependency>
<groupId>org.wicketstuff</groupId>
<artifactId>gchart</artifactId>
<version>7.9.0</version>
</dependency>
<dependency>
<groupId>org.wicketstuff</groupId>
<artifactId>gchart</artifactId>
<version>8.0.0-SNAPSHOT</version>
</dependency>
<repository>
<id>wicketstuff-core-snapshots</id>
<url>ttps://oss.sonatype.org/content/repositories/snapshots</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
AbstractReadOnlyModel<ChartOptions> optionsModel = new AbstractReadOnlyModel<ChartOptions>() {
private static final long serialVersionUID = 1L;
@Override
public ChartOptions getObject() {
ChartOptions opts = new ChartOptions("options");
opts.put("title", "How Much Pizza I Ate Last Night");
return opts;
}
};
AbstractReadOnlyModel<DataTable> dataModel = new AbstractReadOnlyModel<DataTable>() {
private static final long serialVersionUID = 1L;
@Override
public DataTable getObject() {
List<ColumnDeclaration> colDefs;
List<DataRow> rows;
colDefs = new ArrayList<>(2);
colDefs.add(new ColumnDeclaration(ColumnType.STRING, "Topping"));
colDefs.add(new ColumnDeclaration(ColumnType.NUMBER, "Slices"));
rows = new ArrayList<>(5);
rows.add(new DataRow(Arrays.asList(new Object[]{"Mushrooms", 3})));
rows.add(new DataRow(Arrays.asList(new Object[]{"Onions", 1})));
rows.add(new DataRow(Arrays.asList(new Object[]{"Olives", 1})));
rows.add(new DataRow(Arrays.asList(new Object[]{"Zucchini", 1})));
rows.add(new DataRow(Arrays.asList(new Object[]{"Pepperoni", 2})));
return new DataTable("data", colDefs, rows);
}
};
add(new Chart("chartPie", Model.of(ChartType.PIE), optionsModel, dataModel));
<div class="gchart" wicket:id="chartPie"></div>
Dieter Tremel
Path is: /master/gchart-parent