Class ChartCanvas


public class ChartCanvas extends Component<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 Details

  • Constructor Details

    • ChartCanvas

      public ChartCanvas()
      Creates an empty chart canvas with the default settings.
    • ChartCanvas

      public ChartCanvas(String id)
      Creates an empty chart canvas with the default settings using the default language code.
      Parameters:
      id - Canvas ID
    • ChartCanvas

      public ChartCanvas(String id, String language)
      Creates an empty chart canvas with the default settings by specifying the canvas ID.
      Parameters:
      id - Canvas ID
      language - 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 parameter JBStrapParamType.DEFAULT_LANGUAGE.
  • Method Details

    • init

      public void init() throws JavaScriptLoadError
      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 class Component<ChartCanvas>
      Throws:
      JavaScriptLoadError - If there was a JavaScript error during the initialization.
    • getTitleParams

      protected Parameters getTitleParams()
      Returns:
      Parameter class containing chart title settings
    • getLegendParams

      protected Parameters getLegendParams()
      Returns:
      Parameter class containing chart legend settings
    • getTooltipParams

      protected Parameters getTooltipParams()
      Returns:
      Parameter class containing chart tooltip settings
    • setShowBorder

      public ChartCanvas setShowBorder(boolean showBorder)
      Sets if a border should be displayed on the chart canvas. The default setting is that the border is not displayed.
      Parameters:
      showBorder - If true 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

      public ChartCanvas setShowShadow(boolean showShadow)
      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 - If true is specified, a shadow is displayed on the chart canvas If false, 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

      public ChartCanvas setTitle(String title)
      Sets the chart title.
      Parameters:
      title - Chart title If null or an empty string is specified, the chart title is not displayed.
      Returns:
      Chart canvas instance
    • getTitle

      public String getTitle()
      Gets the chart title.
      Returns:
      Chart title or null, if no chart title is specified
    • setTitleFontColor

      public ChartCanvas setTitleFontColor(String color)
      Sets the chart color.
      Parameters:
      color - Chart title color. If no color is specified or null, 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

      public String getTitleFontColor()
      Get the chart title color.
      Returns:
      Chart title color or null, if no color is specified
    • setTitlePosition

      public ChartCanvas setTitlePosition(ChartTitlePosition titlePosition)
      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 If null is specified, the chart title is displayed aligned to the center above the chart. Available positions are listed in ChartTitlePosition.
      Returns:
      Chart canvas instance
    • getTitlePosition

      public ChartTitlePosition getTitlePosition()
      Gets the chart title position.
      Returns:
      Chart title position
    • setTitleFontSize

      public ChartCanvas setTitleFontSize(String fontSize)
      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

      public String getTitleFontSize()
      Gets the chart title font size.
      Returns:
      Chart title font size in the CSS3 format
    • setTitleFontWeight

      public ChartCanvas setTitleFontWeight(FontWeight fontWeight)
      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 enum FontWeight.
      Returns:
      Chart canvas instance
    • getTitleFontWeight

      public FontWeight getTitleFontWeight()
      Gets the chart title font weight.
      Returns:
      Chart title font weight
    • setShowTitle

      public ChartCanvas setShowTitle(boolean showTitle)
      Sets if the chart title should be displayed on the chart. By default, if the specified title is not null or an empty string, it is displayed on the chart.
      Parameters:
      showTitle - If true 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, otherwise false
    • setShowLegend

      public ChartCanvas setShowLegend(boolean showLegend)
      Displays the chart legend. By default, the chart legend is visible.
      Parameters:
      showLegend - If true 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

      public ChartCanvas setLegendPosition(LegendPosition position)
      Sets the legend’s position. By default, the legend’s position is automatically determined.
      Parameters:
      position - Legend position If not specified or null, the legend’s position is automatically determined. Available legend positions are listed in the enum LegendPosition.
      Returns:
      Chart canvas instance
      See Also:
    • getLegendPosition

      public LegendPosition getLegendPosition()
      Gets the legend’s position.
      Returns:
      Legend position
    • setLegendFontColor

      public ChartCanvas setLegendFontColor(String color)
      Sets the legend’s text color.
      Parameters:
      color - Legend text color If not specified or null 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

      public String getLegendFontColor()
      Gets the legend’s text color.
      Returns:
      Legend text color or null if text color is not specified
    • setDualYaxes

      public ChartCanvas setDualYaxes(boolean isDualYAxes)
    • isDualYaxes

      public boolean isDualYaxes()
    • setTooltipType

      public ChartCanvas setTooltipType(TooltipType tooltipType)
      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 enum TooltipType.
      Returns:
      Chart canvas instance
    • getTooltipType

      public TooltipType getTooltipType()
      Gets the tooltip type.
      Returns:
      Tooltip type
    • setTooltipFreezable

      public ChartCanvas setTooltipFreezable(boolean freezable)
      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 - If true is specified, the tooltip is “freezable” If false, 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 Otherwise false.
    • setTooltipRendered

      public ChartCanvas setTooltipRendered(ChartTooltipRenderer renderer)
      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

      protected final void runAfterDrawOnTooltip(Component<?> tooltipComponent)
      Parameters:
      tooltipComponent - Tooltip component
    • runOnShowOnTooltip

      protected final void runOnShowOnTooltip(Component<?> tooltipComponent)
      Parameters:
      tooltipComponent - Tooltip component
    • runOnHideOnTooltip

      protected final void runOnHideOnTooltip(Component<?> tooltipComponent)
      Parameters:
      tooltipComponent - Tooltip component
    • addChart

      public ChartCanvas addChart(BaseChart<?>... charts)
      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

      public ChartCanvas removeChart(String chartName)
      Removes a chart previously added to a canvas by specifying the chart’s name.
      Parameters:
      chartName - The name of the chart to be removed If null is specified or a chart name that is not on the component, the method does nothing.
      Returns:
      Chart canvas component instance
    • removeChart

      public ChartCanvas removeChart(BaseChart<?> chart)
      Removes a chart from the chart canvas component.
      Parameters:
      chart - The chart instance to be removed If null is specified, the method does nothing.
      Returns:
      Chart canvas component
    • getChartByName

      public <T> T getChartByName(String name)
      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

      public List<String> 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 component

      By 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 class Component<ChartCanvas>
    • onShow

      public void onShow()
      Description copied from class: Component
      The operations to be executed after the component is displayed on the client

      By 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 class Component<ChartCanvas>
    • onHide

      public void onHide()
      Description copied from class: Component
      The operations to be executed after the component is hidden on the client

      By 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 class Component<ChartCanvas>
    • runJS

      protected void runJS(String script)
      Parameters:
      script - JavaScript
    • writeHTML

      public boolean writeHTML(StringWriter writer)
      Description copied from class: Component
      Creates the component's HTML equivalent

      This 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 with false. Otherwise, it must return with true.

      Specified by:
      writeHTML in class Component<ChartCanvas>
      Returns:
      If the componentwas drawn, true, otherwise false
    • setHeight

      public ChartCanvas setHeight(Integer height)
      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

      public Integer getHeight()
      Gets the set chart canvas height.
      Returns:
      Chart height in pixels or null, if the chart height is not specified
    • getComponents

      public List<Component<?>> getComponents()
      Description copied from class: Component
      Gets every previously added subcomponent
      Overrides:
      getComponents in class Component<ChartCanvas>
      Returns:
      A collection of every subcomponent that was added to the component. If there are none, the collection will be empty
    • setNoDataFoundText

      public ChartCanvas 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. 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

      public String 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 returns false.
    • 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, otherwise false
    • refreshZoomable

      protected void refreshZoomable()
    • refreshBrushable

      protected void refreshBrushable()