Class ChartCanvas
Use this component to display charts. By default, components are not displayed on the interface. An area (a chart canvas) is reserved for each chart.
- Since:
- 4.0
- Author:
- JBStrap
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
Fields inherited from class com.jbstrap.ui.Component
animation, attributes, backgroundColor, borderColor, color, defaultHotKeyHandler, handlers, hotKeys, styleClasses, textAlign, toolTip, toolTipPosition
-
Constructor Summary
ConstructorDescriptionCreates an empty chart canvas with the default settings.ChartCanvas
(String id) Creates an empty chart canvas with the default settings using the default language code.ChartCanvas
(String id, String language) Creates an empty chart canvas with the default settings by specifying the canvas ID. -
Method Summary
Modifier and TypeMethodDescriptionAdds a chart to the chart canvas component.void
The operations to be executed after the drawing of the component<T> T
getChartByName
(String name) Gets a previously created chart with the specified chart name from the canvas.Gets the chart names added to the canvas.Gets every previously added subcomponentGets the set chart canvas height.Gets the legend’s text color.protected Parameters
Gets the legend’s position.Gets the “no data found” text displayed if there is no data on the chart canvas.getTitle()
Gets the chart title.Get the chart title color.Gets the chart title font size.Gets the chart title font weight.protected Parameters
Gets the chart title position.protected Parameters
Gets the tooltip type.void
init()
The component initialization method.boolean
Checks if the brush feature is enabled on the chart on a canvas.boolean
boolean
Checks if the border is displayed on the chart canvas.boolean
Checks if the legend is visible on the chart canvas.boolean
Checks if the shadow is visible on the chart canvas.boolean
Checks if the chart title is displayed.boolean
Checks if the tooltip freezable feature is enabled.boolean
Checks if the charts on a canvas are zoomable.void
onHide()
The operations to be executed after the component is hidden on the clientvoid
onShow()
The operations to be executed after the component is displayed on the clientprotected void
protected void
removeChart
(BaseChart<?> chart) Removes a chart from the chart canvas component.removeChart
(String chartName) Removes a chart previously added to a canvas by specifying the chart’s name.protected final void
runAfterDrawOnTooltip
(Component<?> tooltipComponent) protected void
protected final void
runOnHideOnTooltip
(Component<?> tooltipComponent) protected final void
runOnShowOnTooltip
(Component<?> tooltipComponent) setDualYaxes
(boolean isDualYAxes) Sets the chart canvas height.setLegendFontColor
(String color) Sets the legend’s text color.setLegendPosition
(LegendPosition position) Sets the legend’s position.setNoDataFoundText
(String noDataFoundText) Sets a text label that is displayed instead of the chart if the framework is unable to display any data on the chart canvas component.setShowBorder
(boolean showBorder) Sets if a border should be displayed on the chart canvas.setShowLegend
(boolean showLegend) Displays the chart legend.setShowShadow
(boolean showShadow) Sets if there should be a shadow on the chart canvas.setShowTitle
(boolean showTitle) Sets if the chart title should be displayed on the chart.Sets the chart title.setTitleFontColor
(String color) Sets the chart color.setTitleFontSize
(String fontSize) Sets the chart title font size.setTitleFontWeight
(FontWeight fontWeight) Sets the chart title font weight.setTitlePosition
(ChartTitlePosition titlePosition) Sets the chart title position.setTooltipFreezable
(boolean freezable) Sets if the user is allowed to freeze a displayed tooltip.setTooltipRendered
(ChartTooltipRenderer renderer) Sets a tooltip renderer method that creates custom tooltips.setTooltipType
(TooltipType tooltipType) Sets the chart’s tooltip type.boolean
writeHTML
(StringWriter writer) Creates the component's HTML equivalentMethods inherited from class com.jbstrap.ui.Component
_hide, _setAttribute, addAllowedRole, addComponent, addComponent, addComponents, addDeniedRole, addHandler, addStyle, addStyleClass, addStyleClasses, clearfix, closeTag, combinateAccess, containsStyle, containsStyleClass, draw, drawSubComponents, error, flattendComponentTree, getAccess, getAccessMode, getAllowedRoles, getAttribute, getAttributes, getBackgroundColor, getBorderColor, getClient, getComponentById, getComponents, getComponentsByClass, getData, getDeniedRoles, getHandlers, getId, getLanguageCode, getName, getParent, getParent, getRegisteredEvents, getStyle, getStyleClasses, getTextAlign, getTextColor, getToolTip, getToolTipPosition, getTypeName, getUI, insertComponentAfter, insertComponentBefore, isAccess, isDrawn, isEnabled, isEventBubbling, isVisible, onHotKeyEventHandler, openTag, redraw, removeAllComponents, removeAllowedRole, removeAllStyleClasses, removeAttribute, removeComponent, removeComponent, removeComponents, removeDeniedRole, removeHandler, removeStyle, removeStyle, removeStyleClass, removeStyleClasses, replaceComponent, replaceStyleClass, runAfterDraw, runJavaScript, runJavaScript, runJavaScript, runOnHide, runOnShow, say, setAttribute, setBackgroundColor, setBorder, setBorderColor, setData, setDisplayType, setEnabled, setEventBubbling, setFlex, setFloating, setHeight100, setHeight25, setHeight50, setHeight75, setHeightAuto, setLanguage, setMargin, setName, setOverflow, setPadding, setParent, setScrollable, setSelectionType, setShadow, setStyle, setTextAlign, setTextColor, setToolTip, setToolTipPosition, setVisible, setWidth100, setWidth25, setWidth50, setWidth75, setWidthAuto, showNotification, showNotification, showProcessIndicator, toggleStyleClass
Methods inherited from class com.jbstrap.core.messagebus.MessageBus
closeMessageBus, messageBusOpened, openMessageBus, renewSubscription, sendMessageToMessageBus, subscribeMessageBus, unsubscribeAllListeners, unsubscribeMessageBus
-
Field Details
-
NO_DATA_TEXT
- See Also:
-
HEIGHT
- See Also:
-
BORDER
- See Also:
-
SHADOW
- See Also:
-
DUAL_Y_AXES
- See Also:
-
TITLE
- See Also:
-
FONT_COLOR
- See Also:
-
FONT_SIZE
- See Also:
-
FONT_WEIGHT
- See Also:
-
POSITION
- See Also:
-
ALIGN
- See Also:
-
SHOW
- See Also:
-
TYPE
- See Also:
-
CUSTOM_HTML
- See Also:
-
FREEZABLE
- See Also:
-
-
Constructor Details
-
ChartCanvas
public ChartCanvas()Creates an empty chart canvas with the default settings. -
ChartCanvas
Creates an empty chart canvas with the default settings using the default language code.- Parameters:
id
- Canvas ID
-
ChartCanvas
Creates an empty chart canvas with the default settings by specifying the canvas ID.- Parameters:
id
- Canvas IDlanguage
- The language code according to which the component is created. If not provided or the entered value is null, the component is created using the framework’s default language. The default language of the framework is set via the JBStrap parameterJBStrapParamType.DEFAULT_LANGUAGE
.
-
-
Method Details
-
init
Description copied from class:Component
The component initialization method.Empty method, only needs to be overwritten when making a custom component, that needs to call an initializing JavaScript on the client side. The method is called by the framework after the component is drawn, but before the afterDraw() method. The use of this method during application development is not allowed. This method is meant for inner use only.
- Overrides:
init
in classComponent<ChartCanvas>
- Throws:
JavaScriptLoadError
- If there was a JavaScript error during the initialization.
-
getTitleParams
- Returns:
- Parameter class containing chart title settings
-
getLegendParams
- Returns:
- Parameter class containing chart legend settings
-
getTooltipParams
- Returns:
- Parameter class containing chart tooltip settings
-
setShowBorder
Sets if a border should be displayed on the chart canvas. The default setting is that the border is not displayed.- Parameters:
showBorder
- Iftrue
is specified, the border is displayed on the chart canvas Otherwise the border is not displayed.- Returns:
- Chart canvas instance
-
isShowBorder
public boolean isShowBorder()Checks if the border is displayed on the chart canvas.- Returns:
- If
true
, the border is displayed on the chart canvas Otherwise the border is not displayed.
-
setShowShadow
Sets if there should be a shadow on the chart canvas. The default setting is that no shadow is displayed on the chart canvas.- Parameters:
showShadow
- Iftrue
is specified, a shadow is displayed on the chart canvas Iffalse
, no shadow is displayed.- Returns:
- Chart canvas instance
-
isShowShadow
public boolean isShowShadow()Checks if the shadow is visible on the chart canvas.- Returns:
- If
true
, the shadow is displayed on the chart canvas Otherwise the shadow is not visible.
-
setTitle
Sets the chart title.- Parameters:
title
- Chart title Ifnull
or an empty string is specified, the chart title is not displayed.- Returns:
- Chart canvas instance
-
getTitle
Gets the chart title.- Returns:
- Chart title or
null
, if no chart title is specified
-
setTitleFontColor
Sets the chart color.- Parameters:
color
- Chart title color. If no color is specified ornull
, the chart title is displayed using the grey theme color. Use the parameter to specify any color in the CSS3 format.- Returns:
- Chart canvas instance
-
getTitleFontColor
Get the chart title color.- Returns:
- Chart title color or
null
, if no color is specified
-
setTitlePosition
Sets the chart title position. The chart title, if specified correctly, is displayed aligned to the center above the chart.- Parameters:
titlePosition
- Chart title position Ifnull
is specified, the chart title is displayed aligned to the center above the chart. Available positions are listed inChartTitlePosition
.- Returns:
- Chart canvas instance
-
getTitlePosition
Gets the chart title position.- Returns:
- Chart title position
-
setTitleFontSize
Sets the chart title font size. The default chart title font size is 14 pixels.- Parameters:
fontSize
- Chart title font size in the CSS3 format- Returns:
- Chart canvas instance
-
getTitleFontSize
Gets the chart title font size.- Returns:
- Chart title font size in the CSS3 format
-
setTitleFontWeight
Sets the chart title font weight. By default, the chart title is displayed with a bold font.- Parameters:
fontWeight
- Chart title font weight Available font weights are listed in the enumFontWeight
.- Returns:
- Chart canvas instance
-
getTitleFontWeight
Gets the chart title font weight.- Returns:
- Chart title font weight
-
setShowTitle
Sets if the chart title should be displayed on the chart. By default, if the specified title is notnull
or an empty string, it is displayed on the chart.- Parameters:
showTitle
- Iftrue
is specified, the marker is displayed on the chart, otherwise not- Returns:
- Chart canvas instance
-
isShowTitle
public boolean isShowTitle()Checks if the chart title is displayed.- Returns:
- If
true
, the chart title is displayed on the chart canvas, otherwisefalse
-
setShowLegend
Displays the chart legend. By default, the chart legend is visible.- Parameters:
showLegend
- Iftrue
is specified, the legend is visible; otherwise not- Returns:
- Chart canvas instance
-
isShowLegend
public boolean isShowLegend()Checks if the legend is visible on the chart canvas.- Returns:
- If
true
, the legend is visible on the chart canvas; otherwise not
-
setLegendPosition
Sets the legend’s position. By default, the legend’s position is automatically determined.- Parameters:
position
- Legend position If not specified ornull
, the legend’s position is automatically determined. Available legend positions are listed in the enumLegendPosition
.- Returns:
- Chart canvas instance
- See Also:
-
getLegendPosition
Gets the legend’s position.- Returns:
- Legend position
-
setLegendFontColor
Sets the legend’s text color.- Parameters:
color
- Legend text color If not specified ornull
is specified, the text is displayed using the theme’s grey color. You can specify any color using the CSS3 format.- Returns:
- Chart canvas instance
-
getLegendFontColor
Gets the legend’s text color.- Returns:
- Legend text color or
null
if text color is not specified
-
setDualYaxes
-
isDualYaxes
public boolean isDualYaxes() -
setTooltipType
Sets the chart’s tooltip type. This setting is used only if a chart is displayed on the chart canvas that supports the set tooltip.- Parameters:
tooltipType
- Tooltip type Available types are listed in the enumTooltipType
.- Returns:
- Chart canvas instance
-
getTooltipType
Gets the tooltip type.- Returns:
- Tooltip type
-
setTooltipFreezable
Sets if the user is allowed to freeze a displayed tooltip. By default, this feature is enabled. The user freezes a tooltip by clicking on a data point. In order to unfreeze it, the user has to click again or hover with the mouse pointer.- Parameters:
freezable
- Iftrue
is specified, the tooltip is “freezable” Iffalse
, the user is not allowed to freeze the tooltip.- Returns:
- Chart canvas instance
-
isTooltipFreezable
public boolean isTooltipFreezable()Checks if the tooltip freezable feature is enabled.- Returns:
- If
true
, the tooltip freezable feature is enabled and the user is allowed to freeze the tooltip on the screen Otherwisefalse
.
-
setTooltipRendered
Sets a tooltip renderer method that creates custom tooltips. If you specify a tooltip creator method, a custom tooltip is displayed to the user. All tooltips created by the method are compatible with all components, their contents can be provided by any arbitrary JBStrap components. If you reset the tooltip type to a built-in tooltip type, the corresponding tooltip is displayed. If you reset the CUSTOM type, the custom-made tooltip is used.- Parameters:
renderer
- Tooltip content creator method- Returns:
- Chart canvas instance
- See Also:
-
runAfterDrawOnTooltip
- Parameters:
tooltipComponent
- Tooltip component
-
runOnShowOnTooltip
- Parameters:
tooltipComponent
- Tooltip component
-
runOnHideOnTooltip
- Parameters:
tooltipComponent
- Tooltip component
-
addChart
Adds a chart to the chart canvas component.- Parameters:
charts
- A list of chart instances to be displayed on the chart canvas- Returns:
- Chart canvas instance
-
removeChart
Removes a chart previously added to a canvas by specifying the chart’s name.- Parameters:
chartName
- The name of the chart to be removed Ifnull
is specified or a chart name that is not on the component, the method does nothing.- Returns:
- Chart canvas component instance
-
removeChart
Removes a chart from the chart canvas component.- Parameters:
chart
- The chart instance to be removed Ifnull
is specified, the method does nothing.- Returns:
- Chart canvas component
-
getChartByName
Gets a previously created chart with the specified chart name from the canvas.- Parameters:
name
- Chart name- Returns:
- Specified chart instance or
null
if there is no chart on the canvas with the specified name
-
getChartNames
Gets the chart names added to the canvas.- Returns:
- A list of chart names added to the canvas If no charts are added to the canvas, the method returns an empty list.
-
afterDraw
public void afterDraw()Description copied from class:Component
The operations to be executed after the drawing of the componentBy default, this is an empty method. It has to be overwritten on a component or page if additional operations have to be executed after the drawing process. One such operation is data retrieval, which shouldn't run in constructors so that the user could see results of an operation or navigation process.
- Overrides:
afterDraw
in classComponent<ChartCanvas>
-
onShow
public void onShow()Description copied from class:Component
The operations to be executed after the component is displayed on the clientBy default, this is an empty method. It has to be overwritten on a component or page, if additional operations have to be executed after the component is displayed. This method is nearly identical to the afterDraw() method, they differ in when they are executed. This method runs after the component is displayed on the client. Meaning that it is executed even if the component isn't redrawn, but only set to be visible after being hidden.
- Overrides:
onShow
in classComponent<ChartCanvas>
-
onHide
public void onHide()Description copied from class:Component
The operations to be executed after the component is hidden on the clientBy default, this is an empty method. It has to be overwritten on a component or page, if additional operations have to be executed after the component is hidden.
- Overrides:
onHide
in classComponent<ChartCanvas>
-
runJS
- Parameters:
script
- JavaScript
-
writeHTML
Description copied from class:Component
Creates the component's HTML equivalentThis method doesn't need to be used during application development. This method is used when developing a custom component. When creating a custom component, this method needs to be implemented. In the parameter (
StringWriter
class) the component's HTML equivalent must be specified, and the method has to return with a Boolean value. This boolean value determines if the component was drawn. If the user doesn't have access right to the component, or if the component couldn't be drawn, it should return withfalse
. Otherwise, it must return withtrue
.- Specified by:
writeHTML
in classComponent<ChartCanvas>
- Returns:
- If the componentwas drawn,
true
, otherwisefalse
-
setHeight
Sets the chart canvas height. By default, the chart height is automatically calculated.- Parameters:
height
- Chart height in pixels If the specified height is smaller or equals than 0, the chart height is automatically calculated.- Returns:
- Chart canvas component instance
-
getHeight
Gets the set chart canvas height.- Returns:
- Chart height in pixels or
null
, if the chart height is not specified
-
getComponents
Description copied from class:Component
Gets every previously added subcomponent- Overrides:
getComponents
in classComponent<ChartCanvas>
- Returns:
- A collection of every subcomponent that was added to the component. If there are none, the collection will be empty
-
setNoDataFoundText
Sets a text label that is displayed instead of the chart if the framework is unable to display any data on the chart canvas component. This happens only of there is no chart assigned to the component or all of the assigned charts are empty (containing no data).- Parameters:
noDataFoundText
- A text to be displayed if the framework is unable to display the chart (no data, empty chart)- Returns:
- Chart canvas component
-
getNoDataFoundText
Gets the “no data found” text displayed if there is no data on the chart canvas.- Returns:
- Text that is displayed only if there is no data on the chart canvas component
-
isZoomable
public boolean isZoomable()Checks if the charts on a canvas are zoomable.- Returns:
- If
true
, charts on the canvas are zoomable If not, the method returnsfalse
.
-
isBrushable
public boolean isBrushable()Checks if the brush feature is enabled on the chart on a canvas.- Returns:
- If
true
, the brush feature is enabled on the charts, otherwisefalse
-
refreshZoomable
protected void refreshZoomable() -
refreshBrushable
protected void refreshBrushable()
-