Class Chart
- All Implemented Interfaces:
Component,ComponentPart,ComponentProperty,HasAnimation,HasData,HasEmphasis
- Direct Known Subclasses:
AbstractChart,RadarChart,SelfPositioningSpecialChart,SunburstChart,XYDataChart
Chart. Since this is a concrete class, this may be directly used for creating a chart of a particular
ChartType. It has got the flexibility that the ChartType can be changed at any time using
setType(ChartType) method.
However, there are concrete derivatives of this class such as PieChart, NightingaleRoseChart etc.
where more chart-specific methods are available and data for the chart is checked more accurately for errors. If
the data set for the chart is of invalid type, a system tries to do its best to adapt that data, but the chart may not
appear if the data conversion fails.
Custom Charts: Any chart may be converted to a custom chart by setting up an item renderer to render the
data point. The item renderer can be specified via setCustomRenderer(String). However, please note that
only a few custom renderers are currently available.
Positioning of charts within the display area of SOChart: Most charts need a CoordinateSystem to
plot on and all CoordinateSystems support positioning (Please see
CoordinateSystem.setPosition(Position)). Those which do not require a CoordinateSystem are called
SelfPositioningChart and supports its own positioning mechanism (Please see
SelfPositioningChart.setPosition(Position)).
- Author:
- Syam
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classClass to represent the Emphasis effect.static classValue-label that can be customized for a chart.static classPosition indicator for labels used in charts. -
Constructor Summary
ConstructorsConstructorDescriptionChart()Create aChartType.Linechart.Chart(AbstractDataProvider<?>... data) Create aChartType.Linechart with the given data.Chart(ChartType type, AbstractDataProvider<?>... data) Create a chart of a given type and data. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd parts of this component to the chart.protected AbstractDataProvider<?> Get the data to embed.protected AbstractDataProvider<?> Get the data that represents the values of this chart.protected intGet the index to get the real data value of this chart.voiddeclareData(Set<AbstractDataProvider<?>> dataSet) Declare the data set owned by thisComponentPartby adding it to theSetprovided.voidEncode the JSON string with the properties of this.getAnimation(boolean create) Get the instance of this property.Get the coordinate system of this chart.final AbstractDataProvider<?>[]getData()Get the current set of data.getEmphasis(boolean create) Get the Emphasis effect of the chart.final ItemStylegetItemStyle(boolean create) Get item style.final Chart.LabelgetLabel(boolean create) Get the label for this chart value.protected StringGet the label name for encoding label if exists.getMarkArea(boolean create) Get the mark area for the chart.getMax()Get the minimum value for this chart.getMin()Get the minimum value for this chart.getName()Set the name of the chart.getTooltip(boolean create) Get the tooltip.getType()Get the type of this chart.protected AbstractDataProvider<?> mainData()Get the main data to be used for rendering.Plot the chart on a given set of axes.plotOn(CoordinateSystem coordinateSystem, Axis... axes) Plot the chart on a given coordinate system.voidsetAnimation(Animation animation) Set it to this instance.voidsetColors(AbstractColor... colors) Set colors for the charts.voidsetCustomRenderer(String renderer) Set a custom renderer for this chart.voidsetData(AbstractDataProvider<?>... data) Set data for the chart.voidsetEmphasis(Emphasis emphasis) Set an Emphasis effect to this chart.voidsetItemStyle(ItemStyle itemStyle) Set item style.voidsetLabel(Chart.Label label) Set the label for this chart value.voidsetMarkArea(MarkArea markArea) Set a customizedMarkAreafor this chart.voidSet the name for this chart.voidsetTooltip(Tooltip tooltip) Set the tooltip.voidSet the type of this chart.protected StringGet the type-value of the chart.voidvalidate()This method is invoked bySOChartto check if the component or part is valid or not.Methods inherited from class com.storedobject.chart.AbstractPart
equals, getId, getLabelTag, getSerial, getZ, hashCode, hasId, setSerial, setZMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.storedobject.chart.ComponentPart
className, getId, getRenderingIndex, getSerial, setRenderingIndex, setSerial
-
Constructor Details
-
Chart
public Chart()Create aChartType.Linechart. -
Chart
Create aChartType.Linechart with the given data.- Parameters:
data- Data to be used (multiples of them for charts that use multi-axis coordinate systems).
-
Chart
Create a chart of a given type and data.- Parameters:
type- type of the chart.data- Data to be used (multiples of them for charts that use multi-axis coordinate systems).
-
-
Method Details
-
setData
Set data for the chart.- Parameters:
data- Data to be used (multiples of them for charts that use multi-axis coordinate systems).
-
getData
-
setCustomRenderer
Set a custom renderer for this chart. Each renderer can be used on a certain type of charts only, may require special data requirements, and you may have to encode the rendering values. The following are the currently supported renderers:
(1) "HBand": Horizontal bands. Applicable to XY charts. Data Point: [y-value, start, end, color], encode { x: 1, y: 0 } (2) "VLine": Single vertical line at a given value. Applicable to XY charts. Single Data Point: [line at (x-value), text label, color], encode { x: 0, y: -1 } (3) "HBar": Horizontal bars. Applicable yo XY charts. Data Point: [y-value, label, start, end, %age completed, bar color] (4) "VAxisLabel": Label bars for the vertical axis. Data Point: [y-value, group label, connected, label, sub-label, bar color], encode { x: -1, y: 0 }- Parameters:
renderer- Name of the renderer.
-
typeValue
-
dataToEmbed
Get the data to embed. This is useful only for those special charts that embed data in the chart itself rather than pointing to the dataset. Example:TreeChart,GaugeChartetc. If null is returned from this method, no data will be embedded.- Returns:
- Data to embed.
-
dataValue
Get the data that represents the values of this chart. This is useful only for those special charts that embed data in the chart itself rather than pointing to the dataset. Example:TreeChart,GaugeChartetc. The default implementation returns the result ofdataToEmbed()if it is not null. Otherwise, it tries to determine it from the axis data if possible.- Returns:
- Data that represents value.
-
mainData
Get the main data to be used for rendering.Note: This is internally used to find out which one of the data set is used by the data-encoder while rendering the chart.
In most case, this will be determined automatically.- Returns:
- Data that represents the main data of the chart.
-
dataValueIndex
protected int dataValueIndex()Get the index to get the real data value of this chart. (In special charts, the actual data value at a data point may be at an index different from 0).- Returns:
- Data value index.
-
encodeJSON
Description copied from interface:ComponentPropertyEncode the JSON string with the properties of this.- Specified by:
encodeJSONin interfaceComponentProperty- Overrides:
encodeJSONin classAbstractPart- Parameters:
sb- Encoded JSON string to be appended to this.
-
getLabelName
Get the label name for encoding label if exists.- Returns:
- Label name. Default is "label".
-
validate
Description copied from interface:ComponentPartThis method is invoked bySOChartto check if the component or part is valid or not.- Specified by:
validatein interfaceComponentPart- Throws:
ChartException- Raises exception if the component or part is not valid.
-
getCoordinateSystem
Get the coordinate system of this chart.Note: Some charts like
PieChart,RadarChartetc. do not have a coordinate system.- Returns:
- Coordinate system.
-
addParts
Description copied from interface:ComponentAdd parts of this component to the chart. This will be invoked if the component was already added to the chart, and it is about to be rendered. -
declareData
Description copied from interface:HasDataDeclare the data set owned by thisComponentPartby adding it to theSetprovided.- Specified by:
declareDatain interfaceHasData- Parameters:
dataSet- Set to which all the data owned by thisComponentPartneeds to be added.
-
getType
-
setType
-
plotOn
Plot the chart on a given coordinate system. (Certain chart types such asChartType.Pie, do not have a coordinate system and thus, this call is not required. Also, instead of using this method, you can use theCoordinateSystem.add(Chart...)method if you want to plot on the default set of axes.)- Parameters:
coordinateSystem- Coordinate system on which the chart will be plotted. (If it was plotted on another coordinate system, it will be removed from it).axes- Axes to be used by the chart. This needs to be specified if the coordinate system has multiple axes of the required type.- Returns:
- Self-reference.
-
plotOn
-
getName
Set the name of the chart. (This will be used in displaying the legend if the legend is enabled in theSOChartor added separately).- Specified by:
getNamein interfaceComponentPart- Overrides:
getNamein classAbstractPart- Returns:
- Name.
-
setName
Set the name for this chart.- Specified by:
setNamein interfaceComponentPart- Parameters:
name- Name.
-
setColors
Set colors for the charts. Certain charts require more than one color, e.g.,PieChart. (Colors are used sequentially and then, circularly).- Parameters:
colors- List of one or more colors.
-
getTooltip
Get the tooltip. (Iftrueis passed as the parameter, a new tooltip will be created if not already exists).- Parameters:
create- Whether to create it or not.- Returns:
- Tooltip.
-
setTooltip
-
getLabel
Get the label for this chart value.- Parameters:
create- Whether to create if not exists or not.- Returns:
- Label.
-
setLabel
Set the label for this chart value.- Parameters:
label- Label.
-
getMin
Get the minimum value for this chart. This is used to determine the minimum value to be used by some other components (such asVisualMap) when rendering occurs. The default implementation tries various ways to determine it automatically.- Returns:
- The minimum value if it is possible to determine. Otherwise, null.
-
getMax
Get the minimum value for this chart. This is used to determine the minimum value to be used by some other components (such asVisualMap) when rendering occurs. The default implementation tries various ways to determine it automatically.- Returns:
- The minimum value if it is possible to determine. Otherwise, null.
-
getItemStyle
Get item style. (Not applicable to certain types of charts).- Parameters:
create- If passed true, a new style is created if not exists.- Returns:
- Item style.
-
setItemStyle
-
getMarkArea
-
setMarkArea
-
getAnimation
Description copied from interface:HasAnimationGet the instance of this property. (Iftrueis passed as the parameter, a new instance will be created if not already exists).- Specified by:
getAnimationin interfaceHasAnimation- Parameters:
create- Whether to create it or not.- Returns:
- Instance.
-
setAnimation
Description copied from interface:HasAnimationSet it to this instance.- Specified by:
setAnimationin interfaceHasAnimation- Parameters:
animation- Instance to set.
-
getEmphasis
Get the Emphasis effect of the chart.- Specified by:
getEmphasisin interfaceHasEmphasis- Parameters:
create- If passed true, a newChart.Emphasiseffect is created if not exists.- Returns:
- Emphasis.
-
setEmphasis
Set an Emphasis effect to this chart.- Specified by:
setEmphasisin interfaceHasEmphasis- Parameters:
emphasis- Emphasis effect to set.
-