GWT Google Charts – TreeMap Chart ”; Previous Next TreeMap is a visual representation of a data tree, where each node may have zero or more children, and one parent (except for the root). Each node is displayed as a rectangle, can be sized and colored according to values that we assign. Sizes and colors are valued relative to all other nodes in the graph. Following is an example of a treemap chart. We have already seen the configurations used to draw a chart in Google Charts Configuration Syntax chapter. Now, let us see an example of a TreeMap Chart. Configurations We”ve used TreeMap class to show a TreeMap chart. TreeMap chart = new TreeMap(); Example HelloWorld.java package com.tutorialspoint.client; import com.google.gwt.core.client.EntryPoint; import com.google.gwt.user.client.ui.RootPanel; import com.googlecode.gwt.charts.client.ChartLoader; import com.googlecode.gwt.charts.client.ChartPackage; import com.googlecode.gwt.charts.client.ColumnType; import com.googlecode.gwt.charts.client.DataTable; import com.googlecode.gwt.charts.client.treemap.TreeMap; import com.googlecode.gwt.charts.client.treemap.TreeMapOptions; public class HelloWorld implements EntryPoint { private TreeMap chart; private void initialize() { ChartLoader chartLoader = new ChartLoader(ChartPackage.TREEMAP); chartLoader.loadApi(new Runnable() { public void run() { // Create and attach the chart chart = new TreeMap(); RootPanel.get().add(chart); draw(); } }); } private void draw() { // Prepare the data DataTable dataTable = DataTable.create(); dataTable.addColumn(ColumnType.STRING, “Location”); dataTable.addColumn(ColumnType.STRING, “Parent”); dataTable.addColumn(ColumnType.NUMBER, “Market trade volume (size)”); dataTable.addColumn(ColumnType.NUMBER, “Market increase/decrease (color)”); dataTable.addRow(“Global”,null,0,0); dataTable.addRow(“America”,”Global”,0,0); dataTable.addRow(“Europe”,”Global”,0,0); dataTable.addRow(“Asia”,”Global”,0,0); dataTable.addRow(“Australia”,”Global”,0,0); dataTable.addRow(“Africa”,”Global”,0,0); dataTable.addRow(“USA”,”America”,52,31); dataTable.addRow(“Mexico”,”America”,24,12); dataTable.addRow(“Canada”,”America”,16,-23); dataTable.addRow(“France”,”Europe”,42,-11); dataTable.addRow(“Germany”,”Europe”,31,-2); dataTable.addRow(“Sweden”,”Europe”,22,-13); dataTable.addRow(“China”,”Asia”,36,4); dataTable.addRow(“Japan”,”Asia”,20,-12); dataTable.addRow(“India”,”Asia”,40,63); dataTable.addRow(“Egypt”,”Africa”,21,0); dataTable.addRow(“Congo”,”Africa”,10,12); dataTable.addRow(“Zaire”,”Africa”,8,10); // Set options TreeMapOptions options = TreeMapOptions.create(); options.setMinColor(“#ff7777”); options.setMidColor(“#ffff77”); options.setMaxColor(“#77ff77”); options.setHeaderHeight(15); options.setShowScale(true); // Draw the chart chart.draw(dataTable, options); chart.setWidth(“400px”); chart.setHeight(“400px”); } public void onModuleLoad() { initialize(); } } Result Verify the result. Print Page Previous Next Advertisements ”;
Category: gwt Googlecharts
GWT Google Charts – Column Charts ”; Previous Next Colummn charts are used to draw colummn based charts. In this section we”re going to discuss following types of colummn based charts. Sr. No. Chart Type / Description 1 Basic Column Basic colummn chart 2 Grouped Column Chart Grouped Colummn chart. 3 Stacked Column Colummn chart having colummn stacked over one another. 4 Negative Stacked Column Colummn chart with negative stack. 5 Diff Column Chart Colummn chart showing Differences. Print Page Previous Next Advertisements ”;
GWT Google Charts – Pie Charts ”; Previous Next Pie charts are used to draw pie based charts. In this section we”re going to discuss following types of pie based charts. Sr. No. Chart Type / Description 1 Basic Pie Basic pie chart. 2 Donut Chart Donut Chart. 3 3D Pie chart 3D Pie chart. 4 Pie chart with exploded slices Pie chart with exploded slices. Print Page Previous Next Advertisements ”;
GWT Google Charts – Line Charts ”; Previous Next Line charts are used to draw line based charts. In this section we”re going to discuss following types of line based charts. Sr. No. Chart Type / Description 1 Basic line Basic line chart. 2 With visible points Chart with visible data points. 3 Customizable background color Chart with customized background color. 4 Customizable line color Chart with customized line color. 5 Customizable axis and tick labels Chart with customized axis and tick labels. 6 Crosshairs Line charts showing crosshairs at data point on selection. 7 Customizable line style Chart with customized line color. 8 Line Charts with curved lines Chart with smooth curve lines. Print Page Previous Next Advertisements ”;
GWT Google Charts – Bubble Charts ”; Previous Next Bubble charts are used to draw bubble based charts. In this section we”re going to discuss following types of bubble based charts. Sr. No. Chart Type / Description 1 Basic Bubble Basic bubble chart. 2 Bubble chart with data labels Bubble chart with data labels. Print Page Previous Next Advertisements ”;
Configuration Syntax
GWT Google Charts – Configuration Syntax ”; Previous Next In this chapter, we will showcase the configuration required to draw a chart using the Google Charts API in GWT. Step 1: Create GWT Application Follow the following steps to update the GWT application we created in GWT – Create Application chapter − Step Description 1 Create a project with a name HelloWorld under a package com.tutorialspoint as explained in the GWT – Create Application chapter. 2 Modify HelloWorld.gwt.xml, HelloWorld.html and HelloWorld.java as explained below. Keep rest of the files unchanged. 3 Compile and run the application to verify the result of the implemented logic. Following is the content of the modified module descriptor src/com.tutorialspoint/HelloWorld.gwt.xml. <?xml version = “1.0” encoding = “UTF-8″?> <module rename-to = ”helloworld”> <inherits name = ”com.google.gwt.user.User”/> <inherits name = ”com.google.gwt.user.theme.clean.Clean”/> <entry-point class = ”com.tutorialspoint.client.HelloWorld”/> <inherits name=”com.googlecode.gwt.charts.Charts”/> <source path = ”client”/> <source path = ”shared”/> </module> Following is the content of the modified HTML host file war/HelloWorld.html. <html> <head> <title>GWT Highcharts Showcase</title> <link rel = “stylesheet” href = “HelloWorld.css”/> <script language = “javascript” src = “helloworld/helloworld.nocache.js”> </head> <body> </body> </html> We”ll see the updated HelloWorld.java in the end after understanding configurations. Step 2: Create Configurations Load Library and create chart Load the library using ChartLoader and then create the chart. ChartLoader chartLoader = new ChartLoader(ChartPackage.CORECHART); chartLoader.loadApi(new Runnable() { public void run() { // Create and attach the chart PieChart chart = new PieChart(); } }); DataTable Configure the details by creating a data table. // Prepare the data DataTable data = DataTable.create(); data.addColumn(ColumnType.STRING, “Browser”); data.addColumn(ColumnType.NUMBER, “Percentage”); data.addRow(“Firefox”, 45.0); data.addRow(“IE”, 26.8); data.addRow(“Chrome”, 12.8); data.addRow(“Safari”, 8.5); data.addRow(“Opera”, 6.2); data.addRow(“Others”, 0.7); // Draw the chart chart.draw(data); Size Configure the width and height to be set. chart.setWidth(“700px”); chart.setHeight(“700px”); Step 3: Add the chart to parent panel. We”re adding the chart to root panel. RootPanel.get().add(chart); Example Consider the following example to further understand the Configuration Syntax − HelloWorld.java package com.tutorialspoint.client; import com.google.gwt.core.client.EntryPoint; import com.google.gwt.user.client.ui.RootPanel; import com.googlecode.gwt.charts.client.ChartLoader; import com.googlecode.gwt.charts.client.ChartPackage; import com.googlecode.gwt.charts.client.ColumnType; import com.googlecode.gwt.charts.client.DataTable; import com.googlecode.gwt.charts.client.corechart.PieChart; public class HelloWorld implements EntryPoint { private PieChart chart; private void initialize() { ChartLoader chartLoader = new ChartLoader(ChartPackage.CORECHART); chartLoader.loadApi(new Runnable() { public void run() { // Create and attach the chart chart = new PieChart(); RootPanel.get().add(chart); draw(); } }); } private void draw() { // Prepare the data DataTable data = DataTable.create(); data.addColumn(ColumnType.STRING, “Browser”); data.addColumn(ColumnType.NUMBER, “Percentage”); data.addRow(“Firefox”, 45.0); data.addRow(“IE”, 26.8); data.addRow(“Chrome”, 12.8); data.addRow(“Safari”, 8.5); data.addRow(“Opera”, 6.2); data.addRow(“Others”, 0.7); // Draw the chart chart.draw(data); chart.setWidth(“400px”); chart.setHeight(“400px”); } public void onModuleLoad() { initialize(); } } Result Verify the result. Print Page Previous Next Advertisements ”;
GWT Google Charts – Stepped Charts ”; Previous Next A stepped area chart is a step based area chart. We”re going to discuss following types of stepped area charts. Sr. No. Chart Type / Description 1 Basic Stepped Chart Basic Stepped Area Chart. 2 Stacked Stepped Chart Stacked Stepped Area Chart. Print Page Previous Next Advertisements ”;
GWT Google Charts – Histogram Charts ”; Previous Next A histogram is a chart that groups numeric data into buckets, displaying the buckets as segmented columns. They”re used to depict the distribution of a dataset as how often values fall into ranges. Google Charts automatically chooses the number of buckets for you. All buckets are equal width and have a height proportional to the number of data points in the bucket. Histograms are similar to column charts in other aspects. In this section we”re going to discuss following types of histogram based charts. Sr. No. Chart Type / Description 1 Basic Histogram Basic Histogram chart. 2 Controlling Color Customized Color of Histrogram Chart. 3 Controlling Buckets Customized Buckets of Histrogram Chart. 4 Multiple Series Histrogram Chart having multiple series. Print Page Previous Next Advertisements ”;
Environment Setup
GWT Google Charts – Environment Setup ”; Previous Next This tutorial will guide you on how to prepare a development environment to start your work with Google Charts and GWT Framework. This tutorial will also teach you how to setup JDK, Tomcat and Eclipse on your machine before you setup GWT Framework − System Requirement GWT requires JDK 1.6 or higher so the very first requirement is to have JDK installed in your machine. JDK 1.6 or above. Memory no minimum requirement. Disk Space no minimum requirement. Operating System no minimum requirement. Follow the given steps to setup your environment to start with GWT application development. Step 1 – Verify Java Installation on your Machine Now open console and execute the following java command. OS Task Command Windows Open Command Console c:> java -version Linux Open Command Terminal $ java -version Mac Open Terminal machine:~ joseph$ java -version Let”s verify the output for all the operating systems Sr.No. OS & Generated Output 1 Windows java version “1.6.0_21” Java(TM) SE Runtime Environment (build 1.6.0_21-b07) Java HotSpot(TM) Client VM (build 17.0-b17, mixed mode, sharing) 2 Linux java version “1.6.0_21” Java(TM) SE Runtime Environment (build 1.6.0_21-b07) ava HotSpot(TM) Client VM (build 17.0-b17, mixed mode, sharing) 3 Mac java version “1.6.0_21” Java(TM) SE Runtime Environment (build 1.6.0_21-b07) Java HotSpot(TM)64-Bit Server VM (build 17.0-b17, mixed mode, sharing) Step 2 – Setup Java Development Kit (JDK) If you do not have Java installed then you can install the Java Software Development Kit (SDK) from Oracle”s Java site: Java SE Downloads. You will find instructions for installing JDK in downloaded files, follow the given instructions to install and configure the setup. Finally set PATH and JAVA_HOME environment variables to refer to the directory that contains java and javac, typically java_install_dir/bin and java_install_dir respectively. Set the JAVA_HOME environment variable to point to the base directory location where Java is installed on your machine. For example Sr.No. OS & Output 1 Windows Set the environment variable JAVA_HOME to C:Program FilesJavajdk1.6.0_21 2 Linux export JAVA_HOME = /usr/local/java-current 3 Mac export JAVA_HOME = /Library/Java/Home Append Java compiler location to System Path. Sr.No. OS & Output 1 Windows Append the string ;%JAVA_HOME%bin to the end of the system variable, Path. 2 Linux export PATH=$PATH:$JAVA_HOME/bin/ 3 Mac not required Alternatively, if you use an Integrated Development Environment (IDE) like Borland JBuilder, Eclipse, IntelliJ IDEA, or Sun ONE Studio, compile and run a simple program to confirm that the IDE knows where you installed Java, otherwise do proper setup as given document of the IDE. Step 3 – Setup Eclipse IDE All the examples in this tutorial have been written using Eclipse IDE. So I would suggest you should have latest version of Eclipse installed on your machine based on your operating system. To install Eclipse IDE, download the latest Eclipse binaries from https://www.eclipse.org/downloads/. Once you downloaded the installation, unpack the binary distribution into a convenient location. For example in C:eclipse on windows, or /usr/local/eclipse on Linux/Unix and finally set PATH variable appropriately. Eclipse can be started by executing the following commands on windows machine, or you can simply double click on eclipse.exe %C:eclipseeclipse.exe Eclipse can be started by executing the following commands on Unix (Solaris, Linux, etc.) machine − $/usr/local/eclipse/eclipse After a successful startup, if everything is fine then it should display result Step 4: Install GWT SDK & Plugin for Eclipse Follow the instructions given at the link Plugin for Eclipse (incl. SDKs) to install GWT SDK & Plugin for Eclipse version installed on your machine. After a successful setup for the GWT plugin, if everything is fine then it should display following screen with Google icon marked with red rectangle. Step 5: Install Google Charts Download the latest Google Charts jar from its MVN Repositorypage and add it to project”s classpath. Add the following entry in <project-name>.gwt.xml file <inherits name = “com.googlecode.gwt.charts.Charts”/> Print Page Previous Next Advertisements ”;