Commit 3b97a83d by Alex Rhodes

added support for stacked bars and legend position

parent f190449b
...@@ -34,8 +34,8 @@ is loaded from Google's servers as required in the Google Terms of Service. ...@@ -34,8 +34,8 @@ is loaded from Google's servers as required in the Google Terms of Service.
</h:head> </h:head>
<h:body> <h:body>
<!-- Charts are passed the type corresponding to the type of chart being rendered, and the chart object --> <!-- Charts are passed the type corresponding to the type of chart being rendered, and the chart object -->
<gc:googleChart type="combo" value="#{googleChartBean.combo}" width="400" height="400"/> <gc:googleChart type="combo" value="#{googleChartBean.combo}" width="1200" height="600"/>
<gc:googleChart type="pie" value="#{googleChartBean.pie}" width="300" height="200"/> <gc:googleChart type="pie" value="#{googleChartBean.pie}" width="600" height="600"/>
</h:body> </h:body>
</html> </html>
...@@ -27,7 +27,7 @@ is loaded from Google's servers as required in the Google Terms of Service. ...@@ -27,7 +27,7 @@ is loaded from Google's servers as required in the Google Terms of Service.
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.alexscottrhodes</groupId> <groupId>com.alexscottrhodes</groupId>
<artifactId>GoogleChartsJSF</artifactId> <artifactId>GoogleChartsJSF</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>1.3</version>
<packaging>war</packaging> <packaging>war</packaging>
<name>Google Charts JSF API</name> <name>Google Charts JSF API</name>
<description>JSF tag wrapper for google charts objects</description> <description>JSF tag wrapper for google charts objects</description>
......
...@@ -133,8 +133,10 @@ public class Builder { ...@@ -133,8 +133,10 @@ public class Builder {
yLabel = ""; yLabel = "";
} }
options += "hAxis: {title:'"+x.getLabel()+"'},"; options += "hAxis: {title:'"+x.getLabel()+"'},";
options += "legend : {position: '" + gcc.getLegendPosition().toString() +"'},";
options += "vAxis: {title:'"+yLabel+"'},"; options += "vAxis: {title:'"+yLabel+"'},";
options += "curveType: '" + gcc.getCurveType().toString() + "',"; options += "curveType: '" + gcc.getCurveType().toString() + "',";
options += "isStacked: " + gcc.isStacked() + ",";
options += "seriesType: '" + x.getDisplayType().toString() + "',"; options += "seriesType: '" + x.getDisplayType().toString() + "',";
String innerSeries ="series:{"; String innerSeries ="series:{";
for(int i = 0; i < gcc.getSeriesList().size(); i++){ for(int i = 0; i < gcc.getSeriesList().size(); i++){
......
...@@ -31,6 +31,7 @@ import java.util.HashMap; ...@@ -31,6 +31,7 @@ import java.util.HashMap;
import com.alexscottrhodes.constructionModel.ChartSeries; import com.alexscottrhodes.constructionModel.ChartSeries;
import com.alexscottrhodes.enums.AxisType; import com.alexscottrhodes.enums.AxisType;
import com.alexscottrhodes.enums.CurveType; import com.alexscottrhodes.enums.CurveType;
import com.alexscottrhodes.enums.LegendPosition;
/** /**
* Model of the Google Combo chart object * Model of the Google Combo chart object
* @author Alex Rhodes * @author Alex Rhodes
...@@ -90,6 +91,17 @@ public class GoogleComboChart { ...@@ -90,6 +91,17 @@ public class GoogleComboChart {
*/ */
private CurveType curveType = CurveType.DEFAULT; private CurveType curveType = CurveType.DEFAULT;
/**
* The LegendPosition to place the legend when rendering the chart.
* See <a href="https://developers.google.com/chart/glossary">Google Charts API</a>
*/
private LegendPosition legendPosition = LegendPosition.RIGHT;
/**
* A boolean for Bar type charts to indicate if the bars should be stacekd or adjacent.
*/
private boolean stacked;
public GoogleComboChart(){ public GoogleComboChart(){
seriesList = new ArrayList<ChartSeries>(); seriesList = new ArrayList<ChartSeries>();
axes = new HashMap<AxisType, ArrayList<ChartSeries>>(); axes = new HashMap<AxisType, ArrayList<ChartSeries>>();
...@@ -200,5 +212,17 @@ public class GoogleComboChart { ...@@ -200,5 +212,17 @@ public class GoogleComboChart {
public void setCurveType(CurveType curveType) { public void setCurveType(CurveType curveType) {
this.curveType = curveType; this.curveType = curveType;
} }
public LegendPosition getLegendPosition() {
return legendPosition;
}
public void setLegendPosition(LegendPosition legendPosition) {
this.legendPosition = legendPosition;
}
public boolean isStacked() {
return stacked;
}
public void setStacked(boolean stacked) {
this.stacked = stacked;
}
} }
...@@ -35,6 +35,7 @@ import com.alexscottrhodes.chartModel.components.PieSlice; ...@@ -35,6 +35,7 @@ import com.alexscottrhodes.chartModel.components.PieSlice;
import com.alexscottrhodes.constructionModel.ChartSeries; import com.alexscottrhodes.constructionModel.ChartSeries;
import com.alexscottrhodes.enums.AxisType; import com.alexscottrhodes.enums.AxisType;
import com.alexscottrhodes.enums.CurveType; import com.alexscottrhodes.enums.CurveType;
import com.alexscottrhodes.enums.LegendPosition;
import com.alexscottrhodes.enums.SeriesDisplayType; import com.alexscottrhodes.enums.SeriesDisplayType;
import com.alexscottrhodes.enums.SeriesType; import com.alexscottrhodes.enums.SeriesType;
/** /**
...@@ -59,7 +60,7 @@ public class Charts { ...@@ -59,7 +60,7 @@ public class Charts {
ChartSeries s = new ChartSeries(SeriesType.NUMBER); // Add a series of ChartSeries s = new ChartSeries(SeriesType.NUMBER); // Add a series of
// numbers // numbers
s.setDisplayType(SeriesDisplayType.LINE); // Make this series a line s.setDisplayType(SeriesDisplayType.BAR); // Make this series a line
s.setLabel("A line of values over time."); s.setLabel("A line of values over time.");
for (Integer i : getRandVals()) { for (Integer i : getRandVals()) {
s.addPoint(i); // Populate with some random numbers s.addPoint(i); // Populate with some random numbers
...@@ -84,6 +85,8 @@ public class Charts { ...@@ -84,6 +85,8 @@ public class Charts {
gcc.addSeries(s); // Add series S gcc.addSeries(s); // Add series S
gcc.addSeries(t);// Add series T gcc.addSeries(t);// Add series T
gcc.addAxisSeries(x, AxisType.X); // Add the X-axis gcc.addAxisSeries(x, AxisType.X); // Add the X-axis
gcc.setStacked(true);
gcc.setLegendPosition(LegendPosition.HIDDEN);
return gcc; return gcc;
} }
......
/*
Google Charts JSF Wrapper
Copyright (C) 2016 Alex Rhodes
https://www.alexscottrhodes.com
Information about this project including set-up and configuration information can be found here:
https://bitbucket.org/alexscottrhodes/googlechartjsf
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
© 2016 "Google" and the Google logo are registered trademarks of Google Inc.
The Google Charts API is used under the Apache 2.0 License above. Google software
is loaded from Google's servers as required in the Google Terms of Service.
*/
package com.alexscottrhodes.enums;
/**
* An Enum for the "curve type" parameter of the Google chart API;
* @author arhodes
*
*/
public enum LegendPosition {
TOP("top"),
LEFT("left"),
RIGHT("right"),
BOTTOM("bottom"),
IN("in"),
HIDDEN("none");
private String plainText;
LegendPosition(String pt){
this.plainText = pt;
}
@Override
public String toString(){
return plainText;
}
}
Manifest-Version: 1.0 Manifest-Version: 1.0
Built-By: Alex Built-By: arhodes
Build-Jdk: 1.8.0_51 Build-Jdk: 1.8.0_92
Created-By: Maven Integration for Eclipse Created-By: Maven Integration for Eclipse
#Generated by Maven Integration for Eclipse #Generated by Maven Integration for Eclipse
#Thu Jul 28 19:10:15 MST 2016 #Wed Aug 03 13:27:26 MST 2016
version=0.0.1-SNAPSHOT version=1.3
groupId=com.alexscottrhodes groupId=com.alexscottrhodes
m2e.projectName=googlechartjsf m2e.projectName=googlechartjsf
m2e.projectLocation=E\:\\Portfolio Workspace\\googlechartjsf m2e.projectLocation=C\:\\workspace\\googlechartjsf
artifactId=GoogleChartsJSF artifactId=GoogleChartsJSF
...@@ -27,7 +27,7 @@ is loaded from Google's servers as required in the Google Terms of Service. ...@@ -27,7 +27,7 @@ is loaded from Google's servers as required in the Google Terms of Service.
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.alexscottrhodes</groupId> <groupId>com.alexscottrhodes</groupId>
<artifactId>GoogleChartsJSF</artifactId> <artifactId>GoogleChartsJSF</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>1.3</version>
<packaging>war</packaging> <packaging>war</packaging>
<name>Google Charts JSF API</name> <name>Google Charts JSF API</name>
<description>JSF tag wrapper for google charts objects</description> <description>JSF tag wrapper for google charts objects</description>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment