Top Description Inners Fields Constructors Methods
javafx.scene.chart

public Class BarChart<X, Y>

extends XYChart<X, Y>
Class Inheritance
Type Parameters
<X>
the category axis value type
<Y>
the data value type
Imports
java.util.*, javafx.scene.AccessibleRole, .Node, javafx.animation.Animation, .FadeTransition, .Interpolator, .KeyFrame, .KeyValue, .ParallelTransition, .Timeline, javafx.application.Platform, javafx.beans.NamedArg, javafx.beans.property.DoubleProperty, javafx.collections.FXCollections, .ObservableList, .ListChangeListener, javafx.geometry.Orientation, javafx.scene.layout.StackPane, javafx.util.Duration, com.sun.javafx.charts.Legend.LegendItem, javafx.css.StyleableDoubleProperty, .CssMetaData, .PseudoClass, .Styleable, .StyleableProperty, javafx.css.converter.SizeConverter

A chart that plots bars indicating data values for a category. The bars can be vertical or horizontal depending on which axis is a category axis.

Adding data with multiple occurences of a category to a series shows the last occurence.

Since
JavaFX 2.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private DoubleProperty
barGap

The gap to leave between bars in the same category

private double
private CategoryAxis
private DoubleProperty
categoryGap

The gap to leave between bars in separate categories

private Timeline
private static final PseudoClass
HORIZONTAL_PSEUDOCLASS_STATE

Pseudoclass indicating this is a horizontal chart.

private static String
private final Orientation
private ParallelTransition
private Map<XYChart.Series<X, Y>, Map<String, XYChart.Data<X, Y>>>
private ValueAxis<T extends Number>
private static final PseudoClass
VERTICAL_PSEUDOCLASS_STATE

Pseudoclass indicating this is a vertical chart.

private Map<XYChart.Data<X, Y>, Double>
Inherited from javafx.scene.chart.XYChart:
DEFAULT_COLORseriesColorMap

Constructor Summary

AccessConstructor and Description
public
BarChart(Axis<X>
The x axis to use
xAxis
,
Axis<Y>
The y axis to use
yAxis
)

Construct a new BarChart with the given axis.

public
BarChart(Axis<X>
The x axis to use
xAxis
,
Axis<Y>
The y axis to use
yAxis
,
ObservableList<XYChart.Series<X, Y>>
The data to use, this is the actual list used so any changes to it will be reflected in the chart
data
)

Construct a new BarChart with the given axis and data.

public
BarChart(Axis<X>
The x axis to use
xAxis
,
Axis<Y>
The y axis to use
yAxis
,
ObservableList<XYChart.Series<X, Y>>
The data to use, this is the actual list used so any changes to it will be reflected in the chart
data
,
double
The gap to leave between bars in separate categories
categoryGap
)

Construct a new BarChart with the given axis and data.

Method Summary

Modifier and TypeMethod and Description
private void
animateDataAdd(XYChart.Data<X, Y> item, Node bar)

private void
public final DoubleProperty
public final DoubleProperty
private Node
createBar(XYChart.Series<X, Y> series, int seriesIndex, final XYChart.Data<X, Y> item, int itemIndex)

private Timeline
createDataRemoveTimeline(final XYChart.Data<X, Y> item, final Node bar, final XYChart.Series<X, Y> series)

pack-priv Legend.LegendItem
createLegendItemForSeries(XYChart.Series<X, Y>
the series for this legend item
series
,
int
the index of the series
seriesIndex
)

Overrides javafx.scene.chart.XYChart.createLegendItemForSeries.

Called by the updateLegend for each series in the chart in order to create new legend item

pack-priv void
dataBeingRemovedIsAdded(XYChart.Data<X, Y> item, XYChart.Series<X, Y> series)

Overrides javafx.scene.chart.XYChart.dataBeingRemovedIsAdded.

This method is called when there is an attempt to add a Data item that was set to be removed, and the removal might not have completed.

protected void
dataItemAdded(XYChart.Series<X, Y>
The series the data item was added to
series
,
int
The index of the new item within the series
itemIndex
,
XYChart.Data<X, Y>
The new data item that was added
item
)

Implements abstract javafx.scene.chart.XYChart.dataItemAdded.

Called when a data item has been added to a series.

protected void
dataItemChanged(XYChart.Data<X, Y>
The data item who was changed
item
)

Implements abstract javafx.scene.chart.XYChart.dataItemChanged.

Called when a data item has changed, ie its xValue, yValue or extraValue has changed.

protected void
dataItemRemoved(final XYChart.Data<X, Y>
The item that has been removed from the series
item
,
final XYChart.Series<X, Y>
The series the item was removed from
series
)

Implements abstract javafx.scene.chart.XYChart.dataItemRemoved.

Called when a data item has been removed from data model but it is still visible on the chart.

public final double
public final double
public static List<CssMetaData<? extends Styleable, ?>>

Returns:

the CssMetaData
getClassCssMetaData
()

Hides javafx.scene.chart.XYChart.getClassCssMetaData.

Gets the CssMetaData associated with this class, which may include the CssMetaData of its superclasses.

public List<CssMetaData<? extends Styleable, ?>>
getCssMetaData()

Overrides javafx.scene.chart.XYChart.getCssMetaData.

Implements javafx.css.Styleable.getCssMetaData.

This method should delegate to Node#getClassCssMetaData() so that a Node's CssMetaData can be accessed without the need for reflection.

private XYChart.Data<X, Y>
getDataItem(XYChart.Series<X, Y> series, int seriesIndex, int itemIndex, String category)

protected void
layoutPlotChildren()

Implements abstract javafx.scene.chart.XYChart.layoutPlotChildren.

Called to update and layout the plot children.

private void
processDataRemove(final XYChart.Series<X, Y> series, final XYChart.Data<X, Y> item)

private void
protected void
seriesAdded(XYChart.Series<X, Y>
The series that has been added
series
,
int
The index of the new series
seriesIndex
)

Implements abstract javafx.scene.chart.XYChart.seriesAdded.

A series has been added to the charts data model.

pack-priv void
seriesBeingRemovedIsAdded(XYChart.Series<X, Y> series)

Overrides javafx.scene.chart.XYChart.seriesBeingRemovedIsAdded.

This method is called when there is an attempt to add series that was set to be removed, and the removal might not have completed.

protected void
seriesChanged(ListChangeListener.Change<? extends XYChart.Series<X, Y>>
a Change instance representing the changes to the series
c
)

Overrides javafx.scene.chart.XYChart.seriesChanged.

Called when each atomic change is made to the list of series for this chart

protected void
seriesRemoved(final XYChart.Series<X, Y>
The series that has been removed
series
)

Implements abstract javafx.scene.chart.XYChart.seriesRemoved.

A series has been removed from the data model but it is still visible on the chart.

public final void
setBarGap(double value)

public final void
setCategoryGap(double value)

private void
updateMap(XYChart.Series<X, Y> series, XYChart.Data<X, Y> item)

Inherited from javafx.scene.chart.XYChart:
alternativeColumnFillVisiblePropertyalternativeRowFillVisiblePropertycreateSeriesRemoveTimeLinecurrentDisplayedExtraValuePropertycurrentDisplayedXValuePropertycurrentDisplayedYValuePropertydataPropertygetCurrentDisplayedExtraValuegetCurrentDisplayedXValuegetCurrentDisplayedYValuegetDatagetDataSizegetDisplayedDataIteratorgetDisplayedSeriesIteratorgetPlotChildrengetSeriesIndexgetSeriesSizegetVerticalGridLinesVisiblegetXAxisgetYAxishorizontalGridLinesVisiblePropertyhorizontalZeroLineVisiblePropertyisAlternativeColumnFillVisibleisAlternativeRowFillVisibleisHorizontalGridLinesVisibleisHorizontalZeroLineVisibleisVerticalZeroLineVisiblelayoutChartChildrenremoveDataItemFromDisplayremoveSeriesFromDisplaysetAlternativeColumnFillVisiblesetAlternativeRowFillVisiblesetCurrentDisplayedExtraValuesetCurrentDisplayedXValuesetCurrentDisplayedYValuesetDatasetHorizontalGridLinesVisiblesetHorizontalZeroLineVisiblesetVerticalGridLinesVisiblesetVerticalZeroLineVisibleupdateAxisRangeupdateLegendverticalGridLinesVisiblePropertyverticalZeroLineVisibleProperty

Field Detail

barGapback to summary
private DoubleProperty barGap

The gap to leave between bars in the same category

bottomPosback to summary
private double bottomPos
categoryAxisback to summary
private CategoryAxis categoryAxis
categoryGapback to summary
private DoubleProperty categoryGap

The gap to leave between bars in separate categories

dataRemoveTimelineback to summary
private Timeline dataRemoveTimeline
HORIZONTAL_PSEUDOCLASS_STATEback to summary
private static final PseudoClass HORIZONTAL_PSEUDOCLASS_STATE

Pseudoclass indicating this is a horizontal chart.

NEGATIVE_STYLEback to summary
private static String NEGATIVE_STYLE
orientationback to summary
private final Orientation orientation
ptback to summary
private ParallelTransition pt
seriesCategoryMapback to summary
private Map<XYChart.Series<X, Y>, Map<String, XYChart.Data<X, Y>>> seriesCategoryMap
valueAxisback to summary
private ValueAxis<T extends Number> valueAxis
VERTICAL_PSEUDOCLASS_STATEback to summary
private static final PseudoClass VERTICAL_PSEUDOCLASS_STATE

Pseudoclass indicating this is a vertical chart.

XYValueMapback to summary
private Map<XYChart.Data<X, Y>, Double> XYValueMap

Constructor Detail

BarChartback to summary
public BarChart(Axis<X> xAxis, Axis<Y> yAxis)

Construct a new BarChart with the given axis. The two axis should be a ValueAxis/NumberAxis and a CategoryAxis, they can be in either order depending on if you want a horizontal or vertical bar chart.

Parameters
xAxis:Axis<X>

The x axis to use

yAxis:Axis<Y>

The y axis to use

BarChartback to summary
public BarChart(Axis<X> xAxis, Axis<Y> yAxis, ObservableList<XYChart.Series<X, Y>> data)

Construct a new BarChart with the given axis and data. The two axis should be a ValueAxis/NumberAxis and a CategoryAxis, they can be in either order depending on if you want a horizontal or vertical bar chart.

Parameters
xAxis:Axis<X>

The x axis to use

yAxis:Axis<Y>

The y axis to use

data:ObservableList<XYChart.Series<X, Y>>

The data to use, this is the actual list used so any changes to it will be reflected in the chart

BarChartback to summary
public BarChart(Axis<X> xAxis, Axis<Y> yAxis, ObservableList<XYChart.Series<X, Y>> data, double categoryGap)

Construct a new BarChart with the given axis and data. The two axis should be a ValueAxis/NumberAxis and a CategoryAxis, they can be in either order depending on if you want a horizontal or vertical bar chart.

Parameters
xAxis:Axis<X>

The x axis to use

yAxis:Axis<Y>

The y axis to use

data:ObservableList<XYChart.Series<X, Y>>

The data to use, this is the actual list used so any changes to it will be reflected in the chart

categoryGap:double

The gap to leave between bars in separate categories

Method Detail

animateDataAddback to summary
private void animateDataAdd(XYChart.Data<X, Y> item, Node bar)
applyNegativeStyleClassback to summary
private void applyNegativeStyleClass(XYChart.Data<X, Y> item)
barGapPropertyback to summary
public final DoubleProperty barGapProperty()
categoryGapPropertyback to summary
public final DoubleProperty categoryGapProperty()
createBarback to summary
private Node createBar(XYChart.Series<X, Y> series, int seriesIndex, final XYChart.Data<X, Y> item, int itemIndex)
createDataRemoveTimelineback to summary
private Timeline createDataRemoveTimeline(final XYChart.Data<X, Y> item, final Node bar, final XYChart.Series<X, Y> series)
createLegendItemForSeriesback to summary
pack-priv Legend.LegendItem createLegendItemForSeries(XYChart.Series<X, Y> series, int seriesIndex)

Overrides javafx.scene.chart.XYChart.createLegendItemForSeries.

Doc from javafx.scene.chart.XYChart.createLegendItemForSeries.

Called by the updateLegend for each series in the chart in order to create new legend item

Parameters
series:XYChart.Series<X, Y>

the series for this legend item

seriesIndex:int

the index of the series

Returns:Legend.LegendItem

new legend item for this series

Annotations
@Override
dataBeingRemovedIsAddedback to summary
pack-priv void dataBeingRemovedIsAdded(XYChart.Data<X, Y> item, XYChart.Series<X, Y> series)

Overrides javafx.scene.chart.XYChart.dataBeingRemovedIsAdded.

Doc from javafx.scene.chart.XYChart.dataBeingRemovedIsAdded.

This method is called when there is an attempt to add a Data item that was set to be removed, and the removal might not have completed.

Annotations
@Override
dataItemAddedback to summary
protected void dataItemAdded(XYChart.Series<X, Y> series, int itemIndex, XYChart.Data<X, Y> item)

Implements abstract javafx.scene.chart.XYChart.dataItemAdded.

Doc from javafx.scene.chart.XYChart.dataItemAdded.

Called when a data item has been added to a series. This is where implementations of XYChart can create/add new nodes to getPlotChildren to represent this data item. They also may animate that data add with a fade in or similar if animated = true.

Parameters
series:XYChart.Series<X, Y>

The series the data item was added to

itemIndex:int

The index of the new item within the series

item:XYChart.Data<X, Y>

The new data item that was added

Annotations
@Override
dataItemChangedback to summary
protected void dataItemChanged(XYChart.Data<X, Y> item)

Implements abstract javafx.scene.chart.XYChart.dataItemChanged.

Doc from javafx.scene.chart.XYChart.dataItemChanged.

Called when a data item has changed, ie its xValue, yValue or extraValue has changed.

Parameters
item:XYChart.Data<X, Y>

The data item who was changed

Annotations
@Override
dataItemRemovedback to summary
protected void dataItemRemoved(final XYChart.Data<X, Y> item, final XYChart.Series<X, Y> series)

Implements abstract javafx.scene.chart.XYChart.dataItemRemoved.

Doc from javafx.scene.chart.XYChart.dataItemRemoved.

Called when a data item has been removed from data model but it is still visible on the chart. Its still visible so that you can handle animation for removing it in this method. After you are done animating the data item you must call removeDataItemFromDisplay() to remove the items node from being displayed on the chart.

Parameters
item:XYChart.Data<X, Y>

The item that has been removed from the series

series:XYChart.Series<X, Y>

The series the item was removed from

Annotations
@Override
getBarGapback to summary
public final double getBarGap()
getCategoryGapback to summary
public final double getCategoryGap()
getClassCssMetaDataback to summary
public static List<CssMetaData<? extends Styleable, ?>> getClassCssMetaData()

Hides javafx.scene.chart.XYChart.getClassCssMetaData.

Gets the CssMetaData associated with this class, which may include the CssMetaData of its superclasses.

Returns:List<CssMetaData<? extends Styleable, ?>>

the CssMetaData

Since
JavaFX 8.0
getCssMetaDataback to summary
public List<CssMetaData<? extends Styleable, ?>> getCssMetaData()

Overrides javafx.scene.chart.XYChart.getCssMetaData.

Implements javafx.css.Styleable.getCssMetaData.

Doc from javafx.scene.chart.XYChart.getCssMetaData.

This method should delegate to Node#getClassCssMetaData() so that a Node's CssMetaData can be accessed without the need for reflection.

Returns:List<CssMetaData<? extends Styleable, ?>>

Doc from javafx.scene.Node.getCssMetaData.

The CssMetaData associated with this node, which may include the CssMetaData of its superclasses.

Annotations
@Override
Since
JavaFX 8.0
getDataItemback to summary
private XYChart.Data<X, Y> getDataItem(XYChart.Series<X, Y> series, int seriesIndex, int itemIndex, String category)
layoutPlotChildrenback to summary
protected void layoutPlotChildren()

Implements abstract javafx.scene.chart.XYChart.layoutPlotChildren.

Doc from javafx.scene.chart.XYChart.layoutPlotChildren.

Called to update and layout the plot children. This should include all work to updates nodes representing the plot on top of the axis and grid lines etc. The origin is the top left of the plot area, the plot area with can be got by getting the width of the x axis and its height from the height of the y axis.

Annotations
@Override
processDataRemoveback to summary
private void processDataRemove(final XYChart.Series<X, Y> series, final XYChart.Data<X, Y> item)
restoreDataValuesback to summary
private void restoreDataValues(XYChart.Data<X, Y> item)
seriesAddedback to summary
protected void seriesAdded(XYChart.Series<X, Y> series, int seriesIndex)

Implements abstract javafx.scene.chart.XYChart.seriesAdded.

Doc from javafx.scene.chart.XYChart.seriesAdded.

A series has been added to the charts data model. This is where implementations of XYChart can create/add new nodes to getPlotChildren to represent this series. Also you have to handle adding any data items that are already in the series. You may simply call dataItemAdded() for each one or provide some different animation for a whole series being added.

Parameters
series:XYChart.Series<X, Y>

The series that has been added

seriesIndex:int

The index of the new series

Annotations
@Override
seriesBeingRemovedIsAddedback to summary
pack-priv void seriesBeingRemovedIsAdded(XYChart.Series<X, Y> series)

Overrides javafx.scene.chart.XYChart.seriesBeingRemovedIsAdded.

Doc from javafx.scene.chart.XYChart.seriesBeingRemovedIsAdded.

This method is called when there is an attempt to add series that was set to be removed, and the removal might not have completed.

Annotations
@Override
seriesChangedback to summary
protected void seriesChanged(ListChangeListener.Change<? extends XYChart.Series<X, Y>> c)

Overrides javafx.scene.chart.XYChart.seriesChanged.

Doc from javafx.scene.chart.XYChart.seriesChanged.

Called when each atomic change is made to the list of series for this chart

Parameters
c:ListChangeListener.Change<? extends XYChart.Series<X, Y>>

a Change instance representing the changes to the series

Annotations
@Override
seriesRemovedback to summary
protected void seriesRemoved(final XYChart.Series<X, Y> series)

Implements abstract javafx.scene.chart.XYChart.seriesRemoved.

Doc from javafx.scene.chart.XYChart.seriesRemoved.

A series has been removed from the data model but it is still visible on the chart. Its still visible so that you can handle animation for removing it in this method. After you are done animating the data item you must call removeSeriesFromDisplay() to remove the series from the display list.

Parameters
series:XYChart.Series<X, Y>

The series that has been removed

Annotations
@Override
setBarGapback to summary
public final void setBarGap(double value)
setCategoryGapback to summary
public final void setCategoryGap(double value)
updateMapback to summary
private void updateMap(XYChart.Series<X, Y> series, XYChart.Data<X, Y> item)
javafx.scene.chart back to summary

private Class BarChart.StyleableProperties

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private static final CssMetaData<BarChart<?, ?>, Number>
private static final CssMetaData<BarChart<?, ?>, Number>
private static final List<CssMetaData<? extends Styleable, ?>>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BAR_GAPback to summary
private static final CssMetaData<BarChart<?, ?>, Number> BAR_GAP
CATEGORY_GAPback to summary
private static final CssMetaData<BarChart<?, ?>, Number> CATEGORY_GAP
STYLEABLESback to summary
private static final List<CssMetaData<? extends Styleable, ?>> STYLEABLES

Constructor Detail

StyleablePropertiesback to summary
private StyleableProperties()