TWiki
>
WebXEO Web
>
XeoPrimerXeoXwc
>
XvwCharts
>
PieChartJava
(2011-04-04,
NicolauGrosskopf
)
(raw view)
E
dit
A
ttach
Tags:
tag this topic
create new tag
,
view all tags
-- Main.PedroRio - 26 Mar 2010 ---++ Java code Associated to a PieChart The grafic XVW components have properties that are fed by a Bean and some properties represent method calls on the Bean side, which have to return Java objects that implement determined inerfaces. In the PieChart case it is needed at least that the property <strong><em>dataSet </em></strong>is filled, and optionaly the property __configOptions__. Assuming a XML definition of the Pie Chart component as the following: <verbatim><xvw:pieChart label="Chart Label" dataSet="#{viewBean.dataSet}" width="500" height="400" type="IMG" configOptions="#{viewBean.configOptions}" > </xvw:pieChart></verbatim> The Bean to use for a pieChart may be something like this (may extend any XEO Bean, it is not required to extend the WebXEO.XEOEditBean): <verbatim>public class PieBean extends WebXEO.XEOEditBean { private PieDataSet dataSet; private IPieChartConfiguration configOptions; public PieBean() { super(); this.dataSet = new PieDataSetImpl(); this.configOptions = new IPieChartConfigImpl(); } public PieDataSet dataSet() { return this.dataSet; } public IPieChartConfiguration configOptions() { return this.configOptions; } }</verbatim> The class _PieDataSetImpl_ is a implementation of the interface _PieDataSet_ for this example, so as the class _IPieChartConfigImpl_ is a implementation of the interface _IPieChartConfiguration_. ---++++ Classe PieDataSetImpl The class PieDataSetImpl definition is very simple once a PieDataSet is essentialy a set of key/value pairs. The values may be saved in a HashMap<String,Integer> and for example purposes we'll have a preference (in numbers) of people between seasons (Summer, Fall and Winter), where, respectively are 190, 200 and 20 people prefering. <verbatim>public class PieDataSetImpl implements PieDataSet { private HashMap<String,Integer> dataSet; public PieDataSetImpl() //Create the Map and fill with values { this.dataSet = new HashMap<String, Integer>(); this.dataSet.put("Summer", 190); this.dataSet.put("Fall", 200); this.dataSet.put("Winter", 20); } @Override //Returns a ame to identify the categories public String getCategoryLabel() { return "Seasons"; } @Override public Number getValue(Comparable<String> key) //Gets a value from the category { return this.dataSet.get(key); } @Override public String getValueLabel() //Returns a name to identify the values for categories { return "Values"; } @Override public List<String> getCategories() //Returns the list of categories, Summer, Fall, Winter { return new Vector<String>(dataSet.keySet()); } }</verbatim> ---++++ Class IPieChartConfigImpl The IPieChartConfigImpl class is a very simple implementation of the configuration interface only to show the using of the same. <verbatim>public class IPieChartConfigImpl implements IPieChartConfiguration { public IPieChartConfigImpl() {} @Override //Defines the grafic background colour. public Color getBackgroundColour() { return Color.gray; } @Override //Maps the color categories, so each slice has it's color public HashMap<String, Color> getColours() { HashMap<String, Color> maps = new HashMap<String, Color>(); maps.put("Winter", Color.black); maps.put("Fall", Color.blue); maps.put("Summer", Color.magenta); return maps; } @Override //If the grafic title should be shown or not public boolean showChartTitle() { return true; } @Override //If the grafic labels are shown or not. public boolean showLabels() { return true; } @Override //returns a expression which can be used to show the tooltips, may contain special variables //in a way to show values(consult interface documentation) public String getTooltipString() { return "$key has value $val which is $percent of total"; } }</verbatim>
E
dit
|
A
ttach
|
P
rint version
|
H
istory
: r3
<
r2
<
r1
|
B
acklinks
|
V
iew topic
|
Ra
w
edit
|
M
ore topic actions
Topic revision: r3 - 2011-04-04
-
NicolauGrosskopf
WebXEO
XEO Primer
-
Instalation
-
Introduction
-
Concepts
-
Architecture
-
XEO Library
-
Deploy to EAR
-
PreferenceStore
XEO - Core
-
XEO Model Reference
-
Security
-
Java API
-
BOL
-
XEOQL (BOQL)
-
Administrating
-
Background Tasks
-
boConfig.xml
-
Web.xml
-
Known Issues
-
XEO Flags
XEO - XWC
- Web Components
- Java Samples
- Custom Components
- Component Plugins
- Internationalization
- Viewer Events
- Value Change Listeners
- XUIServlet
- XeoLocalization
- XvwTemplates
Create New Topic
WebXEO Web
No permission to view
TWiki.WebTopBar
No permission to view
TWiki.WebBottomBar