Skip to content

GoogleCharts Loader API

Dieter Tremel edited this page Dec 11, 2017 · 5 revisions

Google Charts (Loader API)

Note: At the moment there are two Google Chart projects in wicketstuff with the following maven artefacts:

  1. googlecharts

    The first one, realized and based on the Image API, which was deprecated in 2012. See wiki page GoogleCharts for this.

  2. 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.

Maven Artifacts

  • gchart-parent
  • gchart
  • gchart-examples

Documentation

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.

Maven Stable

<dependency>
    <groupId>org.wicketstuff</groupId>
    <artifactId>gchart</artifactId>
    <version>7.9.0</version>
</dependency>

Maven Development

<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>

Java

        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));

HTML

<div class="gchart" wicket:id="chartPie"></div>

Result

Project Maintainers

Dieter Tremel

Source Code

master Branch

Path is: /master/gchart-parent

Clone this wiki locally