Package org.zkoss.chart.plotOptions
Class SeriesLabel
- java.lang.Object
-
- org.zkoss.chart.Optionable
-
- org.zkoss.chart.plotOptions.SeriesLabel
-
- All Implemented Interfaces:
Serializable,OptionDataListener,org.zkoss.json.JSONAware
public class SeriesLabel extends Optionable
Series labels are placed as close to the series as possible in a natural way, seeking to avoid other series. The goal of this feature is to make the chart more easily readable, like if a human designer placed the labels in the optimal position. The series labels currently work with series types having a graph or an area.- Since:
- 7.2.1.0
- Author:
- rudyhuang
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class org.zkoss.chart.Optionable
NOT_NULL_VALUE, options
-
-
Constructor Summary
Constructors Constructor Description SeriesLabel()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description NumbergetConnectorNeighbourDistance()If the label is closer than this to a neighbour graph, draw a connector.NumbergetMaxFontSize()For area-like series, allow the font size to vary so that small areas get a smaller font size.NumbergetMinFontSize()For area-like series, allow the font size to vary so that small areas get a smaller font size.<K,V>
Map<K,V>getStyle()Returns styles for the series label.booleanisConnectorAllowed()Returns whether to allow labels to be placed distant to the graph if necessary, and draw a connector line to the graph.booleanisEnabled()Returns if enable the series label per series.booleanisOnArea()Returns whether to draw the label on the area of an area series.voidsetConnectorAllowed(boolean connectorAllowed)Sets whether to allow labels to be placed distant to the graph if necessary, and draw a connector line to the graph.voidsetConnectorNeighbourDistance(Number connectorNeighbourDistance)If the label is closer than this to a neighbour graph, draw a connector.voidsetEnabled(boolean enabled)Sets if enable the series label per series.voidsetMaxFontSize(Number maxFontSize)For area-like series, allow the font size to vary so that small areas get a smaller font size.voidsetMinFontSize(Number minFontSize)For area-like series, allow the font size to vary so that small areas get a smaller font size.voidsetOnArea(boolean onArea)Sets whether to draw the label on the area of an area series.voidsetStyle(String style)Set styles for the series label.<K,V>
voidsetStyle(Map<K,V> style)Set styles for the series label.-
Methods inherited from class org.zkoss.chart.Optionable
addExtraAttr, addOptionDataListener, clearOptonDataListener, clone, containsKey, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, getAttr, getAttr, getClientState, getExtraAttr, merge, onChange, removeExtraAttr, removeKey, removeOptionDataListener, setAttr, setAttr, setAttr, setAttr, toJSONString, toString
-
-
-
-
Method Detail
-
isConnectorAllowed
public boolean isConnectorAllowed()
Returns whether to allow labels to be placed distant to the graph if necessary, and draw a connector line to the graph. Setting this option to true may decrease the performance significantly, since the algorithm with systematically search for open spaces in the whole plot area. Visually, it may also result in a more cluttered chart, though more of the series will be labeled.Default: false
-
setConnectorAllowed
public void setConnectorAllowed(boolean connectorAllowed)
Sets whether to allow labels to be placed distant to the graph if necessary, and draw a connector line to the graph. Setting this option to true may decrease the performance significantly, since the algorithm with systematically search for open spaces in the whole plot area. Visually, it may also result in a more cluttered chart, though more of the series will be labeled.
-
getConnectorNeighbourDistance
public Number getConnectorNeighbourDistance()
If the label is closer than this to a neighbour graph, draw a connector.Default: 24
-
setConnectorNeighbourDistance
public void setConnectorNeighbourDistance(Number connectorNeighbourDistance)
If the label is closer than this to a neighbour graph, draw a connector.
-
isEnabled
public boolean isEnabled()
Returns if enable the series label per series.Default: true
-
setEnabled
public void setEnabled(boolean enabled)
Sets if enable the series label per series.
-
getMaxFontSize
public Number getMaxFontSize()
For area-like series, allow the font size to vary so that small areas get a smaller font size. The default applies this effect to area-like series but not line-like series.Default: null
-
setMaxFontSize
public void setMaxFontSize(Number maxFontSize)
For area-like series, allow the font size to vary so that small areas get a smaller font size. The default applies this effect to area-like series but not line-like series.
-
getMinFontSize
public Number getMinFontSize()
For area-like series, allow the font size to vary so that small areas get a smaller font size. The default applies this effect to area-like series but not line-like series.Default: null
-
setMinFontSize
public void setMinFontSize(Number minFontSize)
For area-like series, allow the font size to vary so that small areas get a smaller font size. The default applies this effect to area-like series but not line-like series.
-
isOnArea
public boolean isOnArea()
Returns whether to draw the label on the area of an area series. By default it is drawn on the area. Set it to false to draw it next to the graph instead.Default: true
-
setOnArea
public void setOnArea(boolean onArea)
Sets whether to draw the label on the area of an area series. By default it is drawn on the area. Set it to false to draw it next to the graph instead.
-
getStyle
public <K,V> Map<K,V> getStyle()
Returns styles for the series label. The color defaults to the series color, or a contrast color if onArea. Default:font-weight: 'bold'
- Type Parameters:
K- type for the keyif style was set using
setStyle(String), type will be Stringif style was set using
setStyle(Map), type will be the same as the type from the key of the mapif style was not set, default style will be applied, and type will be String
V- type for the valueif style was set using
setStyle(String), type will be Stringif style was set using
setStyle(Map), type will be the same as the type from the key of the mapif style was not set, default style will be applied, and type will be String
-
setStyle
public void setStyle(String style)
Set styles for the series label. This method allows simple settings likelabel.setStyle("fontWeight: 'bold'; color: 'white'; textShadow: '0px 1px 2px black'");In the format of CSS key:value, and ";" separating multiple key:value pairs, if you have more a complex CSS styling, we recommend using
setStyle(Map)- Parameters:
style- one or many CSS key:value pairs in a single line string format
-
setStyle
public <K,V> void setStyle(Map<K,V> style)
Set styles for the series label. This method allows complex styling like:
which will generate the final results like:Map<String, Object> styles = new HashMap<String, Object>(); styles.put("fill", "#E8E8EA"); styles.put("stroke", "#6E6E78"); styles.put("stroke-width", "1"); styles.put("r", "0"); Map<String, Object> states = new HashMap<String, Object>(); Map<String, String> hover = new HashMap<String, String>(); hover.put("fill", "#F4F4F6"); hover.put("stroke", "#6E6E78"); hover.put("stroke-width", "1"); hover.put("r", "0"); states.put("hover", hover); styles.put("states", states); Map<String, String> style = new HashMap<String, String>(); style.put("color", "#4D5663"); style.put("fontSize", "12px"); style.put("fontFamily", "'Arial'"); style.put("fontWeight", "normal"); style.put("padding", "10px"); styles.put("style", style);{ "fill": "#E8E8EA", "stroke": "#6E6E78", "stroke-width": "1", "r": "0", "states": { "hover": { "fill": "#F4F4F6", "stroke": "#6E6E78", "stroke-width": "1", "r": "0" } }, "style": { "color": "#4D5663", "fontSize": "12px", "fontFamily": "'Arial'", "fontWeight": "normal", "padding": "10px" } }- Type Parameters:
K- Type for the key, usually StringV- Type for the value, usually String. For nested maps, use Object or any other type.- Parameters:
style- the style object
-
-