Class ChartOptions
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- java.util.HashMap<String,Object>
-
- org.wicketstuff.gchart.gchart.options.ChartOptions
-
- All Implemented Interfaces:
Serializable,Cloneable,Map<String,Object>,IClusterable,JavaScriptable,Jsonable
public class ChartOptions extends HashMap<String,Object> implements IClusterable, JavaScriptable, Jsonable
Specialization ofHashMap<String, Object>to hold chart options and generate JSON to represent them. ChartOptions can be nested, so more complex settings are realized in JSON output. For instance
results inChartOptions opts = new ChartOptions("options"); opts.put("title", "Metar Temperatur"); // opts.put("width", 400); // opts.put("height", 300); ChartOptions hAxisOpts = new ChartOptions(); ChartOptions vAxisOpts = new ChartOptions(); ChartOptions vAxisGridline = new ChartOptions(); vAxisGridline.put("count", 8); vAxisOpts.put("gridlines", vAxisGridline); opts.put("vAxis", vAxisOpts);var options = {"vAxis":{"gridlines":{"count":8}},"title":"Metar Temperatur"};The root instance must have a name so an identifier for the variable ist given. Values can be models (
instanceof IModel). If the ChartOptions are rendered to JavaScript bytoJavaScript(),getObject()will be applied automatically to the models to retreive the value that goes to JavaScript. This is even possible if values are JSONObjects with Models as values, since a subclass ofJSONStringeris used, that dereferences the models before rendering the value.- Author:
- Dieter Tremel
- See Also:
ModelAwareJSONStringer, Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object,V extends Object>
-
-
Constructor Summary
Constructors Constructor Description ChartOptions()Default constructor.ChartOptions(String name)Constructor defining name.ChartOptions(String name, Map<? extends String,? extends Object> m)Constructor from another map.ChartOptions(ChartOptions m)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object obj)static ChartOptionsfromJson(com.github.openjson.JSONObject json)Build instance from a JSONobject.static ChartOptionsfromJson(String json)Build an instance from a JSON string for instance as seen in tutorials.ChartOptionsgetModelObjects()Create a deep copy of the instance, where all models (instanceof IModel) are replaced with there value bygetObject().StringgetName()inthashCode()voidsetName(String name)StringtoJavaScript()Return the JavaScript part.StringtoJavaScript(String varname)Generate declaration js for options variable.com.github.openjson.JSONObjecttoJSON()Create the JSON serialization of the instance.-
Methods inherited from class java.util.HashMap
clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
-
Methods inherited from class java.util.AbstractMap
toString
-
-
-
-
Constructor Detail
-
ChartOptions
public ChartOptions()
Default constructor.
-
ChartOptions
public ChartOptions(String name)
Constructor defining name.- Parameters:
name- The name is used to render a variable name in javascript.
-
ChartOptions
public ChartOptions(ChartOptions m)
-
-
Method Detail
-
fromJson
public static ChartOptions fromJson(String json)
Build an instance from a JSON string for instance as seen in tutorials. For users, that find coding in JSON easier than building nested ChartOptions, this my be an additional offer. Implemented asfromJson(new JSONObject(json));, seefromJson(com.github.openjson.JSONObject).- Parameters:
json- JSON string like{'title':'How Much Pizza I Ate Last Night','width':400,'height':300}- Returns:
- New instance with data from the JSON String.
-
fromJson
public static ChartOptions fromJson(com.github.openjson.JSONObject json)
Build instance from a JSONobject.- Parameters:
json- JSON object to build map from. If this contains other JSONObjects nested, a corresponding nested structure of ChartOptions will be built.- Returns:
- New instance with data from the JSONObject.
-
getName
public String getName()
-
setName
public void setName(String name)
-
equals
public boolean equals(Object obj)
-
hashCode
public int hashCode()
-
getModelObjects
public ChartOptions getModelObjects()
Create a deep copy of the instance, where all models (instanceof IModel) are replaced with there value bygetObject().- Returns:
- Deep copy with all models replaced.
-
toJavaScript
public String toJavaScript()
Description copied from interface:JavaScriptableReturn the JavaScript part.- Specified by:
toJavaScriptin interfaceJavaScriptable- Returns:
- JavaScript String for use as part of chart declaration.
-
toJavaScript
public String toJavaScript(String varname)
Generate declaration js for options variable.- Parameters:
varname- Name of options variable identifier.- Returns:
- Declaration js
-
-