Class GaugeChart
- All Implemented Interfaces:
DataDescriptorCallback
,ClickableChartData<GaugeChart>
,MultiSeriesChart<GaugeChart,
GaugeSeries>
A gauge chart is a chart resembling an analog instrument where one or more needles indicate the measured value. The chart is capable of displaying
multiple series, but each series can only contain one type of data. Each series is represented on the chart as a separate needle. Also, you can specify
one or more ranges and sections. These are represented as colored arcs on the circumference of
the instrument’s scale. By default, if you do not specify any sections, the chart area is divided into three parts of equal size. You can specify
the starting value and color of each section. The default colors are red, yellow and green. The chart’s default display is setting is a speedometer gauge
speedometer
. A speedometer’s readings increase from the left to the right, the minimum value being on the left side and the maximum value being on
the right side. If the specified value does not fall into to the measured range (it is below the lower threshold or above the upper threshold), the needle points to
the lower or upper thresholds. You can also modify the visualization type, making it possible to change the shape of the instrument. The instrument can also
be a semicircle facing the right or the left,
or even a horizontal semicircle.
This chart is does not allow you to modify the tooltip, you can only use a DOT
. However, the chart
enables you to create custom tooltips using any JBStrap component. If you want to display a tooltip that is different from the default one,
you need to create it on your own using ChartTooltipRenderer
. You only need to implement one method which returns the tooltip as a component.
In order to do this, you can reuse any JBStrap component. It is possible to display a button, a list or even another chart on the tooltip.
The chart also supports click event handling. This means that you can implement server-side business logic for the event that is triggered when a user clicks on
chart data. This is when a ChartClick
event is triggered. This event provides you information on where and which chart
the user clicked on. This can be reused in various ways, e.g. to update a list.
- Since:
- 4.0
- Author:
- JBStrap
- See Also:
-
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
Fields inherited from class com.jbstrap.ui.components.charts.SeriesBasedChart
categoryColumn, dataDescriptor, defaultFilterCriteria, filterCriteria, series
Fields inherited from class com.jbstrap.ui.components.charts.BaseChart
brushable, canvas, defaultTooltipType, handlers, NAME, params, supportedTooltipTypes, tooltipContent, tooltipType, zoomable
-
Constructor Summary
ConstructorDescriptionGaugeChart
(String name) Creates the gauge chart.GaugeChart
(String name, DataDescriptor dataDescriptor, String categoryColumnName) Creates the gauge chart component and sets the name of the DataDescriptor and that of the category column. -
Method Summary
Modifier and TypeMethodDescriptionAdds a new series to the chart.changeSectionName
(String oldName, String newName) Modifies the section’s name.createSection
(String name, double start) Creates a new chart section.createSection
(String name, double start, String color) Creates a new chart section.Gets the previously defined color scheme.Gets the default color scheme.int
Gets the rounding radius of chart section corners.double
getMax()
Gets the chart’s maximum value.double
getMin()
Gets the chart’s minimum value.double
Gets the size of the padding between chart sections.getSectionByName
(String name) Gets a section of the chart by its specified name.Gets the chart’s sections.Gets the thickness of the gauge chart arc.Gets the number of ticks displayed on the chart.getType()
Gets the chart’s display type.int
Gets the font size of measured gauge reading.protected void
init()
Chart initialization.boolean
Checks if section data labels are visible on the chart.boolean
Checks if the needle’s value label (the measured reading of the gauge) is also displayed on the chart.protected void
removeSections
(String name) Removes the specified section from the chart.setColorRange
(String... colors) Sets a custom color scheme.setColorTemplate
(ColorTemplate template) Set the chart’s color scheme.setCornerRadius
(int radius) Sets the rounding radius for chart section corners.setMax
(double max) The maximum gauge chart reading (end value).setMin
(double min) The minimum gauge chart reading (starting value).setPadding
(double padding) Sets the size of the padding between chart sections.setScaleStartValue
(String name, double start) Modifies the section’s initial value.setSectionColor
(String name, String color) Sets a chart’s section color.setShowDataLabels
(boolean showDataLabels) Sets if the chart sections should display data labels.setShowValueLabel
(boolean showValueLabel) Sets if value labels should be displayed on the chart.setThickness
(Integer thickness) Sets the thickness of the arc on the chart.setTickCount
(int tickCount) Sets the number of ticks displayed on the chart.setTickCount
(TickNumbers tickNumber) Sets the number of ticks based on the tick type.setType
(GaugeChartType type) Sets the chart’s display type.setValueLabelSize
(int size) Sets the displayed value label’s font size.Methods inherited from class com.jbstrap.ui.components.charts.SeriesBasedChart
_addSeries, _getSeries, _getSeriesNames, clear, fetchData, generateJSON, getCategoryColumnName, getDataColumnBySeriesName, getDataDescriptor, getDefaultFilterCriteria, getFilterCriteria, onError, onSuccess, refreshData, registerDataColumn, removeSeries, setDataDescriptor, setDefaultFilterCriteria, setFilterCriteria
Methods inherited from class com.jbstrap.ui.components.charts.BaseChart
getCanvas, getDefaultTooltipType, getHandlers, getName, getSupportedTooltipTypes, runJs, setParent
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.jbstrap.ui.components.charts.ClickableChartData
addClickHandler
Methods inherited from interface com.jbstrap.ui.components.charts.MultiSeriesChart
getSeries, getSeriesNames
-
Field Details
-
MIN
- See Also:
-
MAX
- See Also:
-
SECTIONS
- See Also:
-
TYPE
- See Also:
-
TICK_COUNT
- See Also:
-
SHOW_VALUE_LABLES
- See Also:
-
VALUE_LABEL_SIZE
- See Also:
-
SHOW_DATA_LABELS
- See Also:
-
PADDING
- See Also:
-
CORNER_RADIUS
- See Also:
-
THICKNESS
- See Also:
-
COLOR_TEMPLATE
- See Also:
-
COLOR_RANGE
- See Also:
-
-
Constructor Details
-
GaugeChart
Creates the gauge chart.- Parameters:
name
- Chart name It is mandatory to specify the chart name and it must be unique within theChartCanvas
. Later on, you can reference the chart with the name specified here.- Throws:
NullPointerException
- Thrown if the specified name isnull
or it is an empty string
-
GaugeChart
Creates the gauge chart component and sets the name of the DataDescriptor and that of the category column.- Parameters:
name
- Chart name It is mandatory to specify the chart name and it must be unique within theChartCanvas
. Later on, you can reference the chart with the name specified here.dataDescriptor
- The DataDescriptor that contains the chart datacategoryColumnName
- The name of the DataDescriptor containing X axis data If not specified, ornull
is specified, the framework starts looking for the “CATEGORY” column.- Throws:
NullPointerException
- Thrown if the specified name isnull
or it is an empty stringIllegalArgumentException
- Thrown if the column specified in the categoryColumnName parameter is not found in the DataDescriptor or if the categoryColumnName parameter is not specified and no “CATEGORY” column is found in the DataDescriptor.
-
-
Method Details
-
getSections
Gets the chart’s sections.- Returns:
- A list containing the chart’s section data
-
init
protected void init()Description copied from class:BaseChart
Chart initialization.- Specified by:
init
in classBaseChart<GaugeChart>
-
setType
Sets the chart’s display type. The default display setting for the chart isGaugeChartType.SPEEDOMETER
.- Parameters:
type
- Display type Available types are listed in the enumGaugeChartType
. Ifnull
is specified, the default settingGaugeChartType.SPEEDOMETER
will apply.- Returns:
- Chart instance
-
getType
Gets the chart’s display type.- Returns:
- Chart display type
-
setTickCount
Sets the number of ticks based on the tick type. The default display setting for the chart isTickNumbers.SECTIONED
.- Parameters:
tickNumber
- The number of ticks on the chart Available values are listed in the enumTickNumbers
. Ifnull
is specified, the chart is displayed with the default settings.- Returns:
- Chart instance
-
setTickCount
Sets the number of ticks displayed on the chart.- Parameters:
tickCount
- The number of ticks on the chart If a number smaller than 0 is specified, the number of ticks is automatically determined using theTickNumbers.SECTIONED
setting.- Returns:
- Chart instance
-
getTickNumbers
Gets the number of ticks displayed on the chart.- Returns:
- The number of ticks as an Integer or a member of the
TickNumbers
enum if the number of ticks is automatically determined based on a type
-
setShowValueLabel
Sets if value labels should be displayed on the chart. The value is displayed below the needle on the scale. By default, this setting is not enabled. This setting is applicable only if there is one needle on the chart.- Parameters:
showValueLabel
- Iftrue
is specified, the value label appears on the chart alongside the needle Otherwise, the value label is not visible.- Returns:
- Chart instance
-
isShowValueLabel
public boolean isShowValueLabel()Checks if the needle’s value label (the measured reading of the gauge) is also displayed on the chart.- Returns:
- If
true
, the measured reading is also displayed on the chart Otherwise itfalse
.
-
setValueLabelSize
Sets the displayed value label’s font size. The default font size setting is 28 pixels for the measured gauge reading.- Parameters:
size
- The font size of the measured gauge reading in pixels- Returns:
- Chart instance
-
getValueLabelSize
public int getValueLabelSize()Gets the font size of measured gauge reading.- Returns:
- The font size of the measured gauge reading in pixels
-
setShowDataLabels
Sets if the chart sections should display data labels. The default setting for data labels is enabled.- Parameters:
showDataLabels
- Iftrue
is specified, data labels are on Iffalse
, data labels are turned off.- Returns:
- Chart instance
-
isShowDataLabels
public boolean isShowDataLabels()Checks if section data labels are visible on the chart.- Returns:
- If
true
, section data labels are on Otherwise itfalse
.
-
setPadding
Sets the size of the padding between chart sections. The default padding for chart sections is 0.01.- Parameters:
padding
- Padding (between 0 and 1)- Returns:
- Chart instance
-
getPadding
public double getPadding()Gets the size of the padding between chart sections.- Returns:
- Padding (between 0 and 1)
-
setCornerRadius
Sets the rounding radius for chart section corners. The default rounding setting is 0, that is, chart section corners are not rounded.- Parameters:
radius
- Rounding radius of chart section corners in pixels- Returns:
- Chart instance
-
getCornerRadius
public int getCornerRadius()Gets the rounding radius of chart section corners.- Returns:
- Rounding radius of chart section corners in pixels
-
setThickness
Sets the thickness of the arc on the chart. The default thickness setting for the gauge chart arc is 38%.- Parameters:
thickness
- The thickness of the gauge chart arc in percentage If 0 or a smaller value is specified, the chart does not show. If 100 or a greater value is specified, the chart fill all available area.- Returns:
- Chart instance
-
getThickness
Gets the thickness of the gauge chart arc.- Returns:
- Chart arc thickness in percentage
-
setColorTemplate
Set the chart’s color scheme. The default color scheme setting for the chart isColorTemplate.RED_TO_GREEN
: lower values are displayed as red, higher values are displayed as green. The section color between the first and the last sections is automatically determined.- Parameters:
template
- The chart’s color scheme Available values are listed in the enumColorTemplate
. Ifnull
is specified, the chart uses the default color scheme.- Returns:
- Chart instance
-
getColorTemplate
Gets the default color scheme.- Returns:
- The chart’s default color scheme
-
setColorRange
Sets a custom color scheme. This method sets the chart’s section colors using the colors specified in the parameters. If fewer colors are specified than the number of sections on the chart, the “missing” section colors are automatically updated with colors between the specified ones.- Parameters:
colors
- A list of section colors as defined by the CSS3 standard- Returns:
- Chart instance
-
getColorRange
Gets the previously defined color scheme.- Returns:
- A list containing the chart’s previously specified color scheme If there is no previously specified color scheme, the method returns
null
.
-
addSeries
Adds a new series to the chart.- Specified by:
addSeries
in interfaceMultiSeriesChart<GaugeChart,
GaugeSeries> - Parameters:
series
- Series instance to be added- Returns:
- Chart
-
setMin
The minimum gauge chart reading (starting value). The default minimum value is 0.- Parameters:
min
- Chart’s minimum value- Returns:
- Chart instance
-
getMin
public double getMin()Gets the chart’s minimum value.- Returns:
- Chart’s minimum value
-
setMax
The maximum gauge chart reading (end value).- Parameters:
max
- Displayed maximum value- Returns:
- Chart instance
-
getMax
public double getMax()Gets the chart’s maximum value.- Returns:
- The chart’s maximum value
-
createSection
Creates a new chart section. By default, the chart is divided into three sections of equal size. By adding sections, you further divide the chart. Default (initial) sections are deleted and only the new (added) sections remain.- Parameters:
name
- Section namestart
- Starting value of the section- Returns:
- Chart instance
-
createSection
Creates a new chart section. By default, the chart is divided into three sections of equal size. By adding sections, you further divide the chart. Default (initial) sections are deleted and only the new (added) sections remain.- Parameters:
name
- Section namestart
- Starting value of the sectioncolor
- Section color as defined by the CSS3 standard- Returns:
- Chart instance
-
getSectionByName
Gets a section of the chart by its specified name.- Parameters:
name
- Section name- Returns:
- The data of the specified section or
null
if there is no section with the specified name
-
removeSections
Removes the specified section from the chart. If the last section is removed, the chart is automatically divided into three sections of equal size.- Parameters:
name
- Section name- Returns:
- Chart instance
-
setSectionColor
Sets a chart’s section color.- Parameters:
name
- Section name Hanull
, or a name is specified that has no corresponding sections on the chart, the method does nothing.color
- Section color as defined by the CSS3 standard- Returns:
- Chart instance
-
setScaleStartValue
Modifies the section’s initial value.- Parameters:
name
- Section name Hanull
, or a name is specified that has no corresponding sections on the chart, the method does nothing.start
- Starting value of the section- Returns:
- Chart instance
-
changeSectionName
Modifies the section’s name.- Parameters:
oldName
- The original name of the section you want to modify Hanull
, or a name is specified that has no corresponding sections on the chart, the method does nothing.newName
- New section name- Returns:
- Chart instance
-
refreshScale
protected void refreshScale()
-