--- old/modules/javafx.controls/src/main/java/javafx/scene/chart/AreaChart.java 2017-03-09 14:44:08.938173401 -0800
+++ new/modules/javafx.controls/src/main/java/javafx/scene/chart/AreaChart.java 2017-03-09 14:44:08.806173399 -0800
@@ -154,7 +154,7 @@
return (number == null) ? nullDefault : number.doubleValue();
}
- /** @inheritDoc */
+ /** {@inheritDoc} */
@Override protected void updateAxisRange() {
final Axis xa = getXAxis();
final Axis ya = getYAxis();
@@ -330,7 +330,7 @@
//Note: better animation here, point should move from old position to new position at center point between prev and next symbols
}
- /** @inheritDoc */
+ /** {@inheritDoc} */
@Override protected void dataItemChanged(Data item) {
}
@@ -415,7 +415,7 @@
}
}
- /** @inheritDoc */
+ /** {@inheritDoc} */
@Override protected void layoutPlotChildren() {
List constructedPath = new ArrayList<>(getDataSize());
for (int seriesIndex=0; seriesIndex < getDataSize(); seriesIndex++) {
--- old/modules/javafx.controls/src/main/java/javafx/scene/chart/BarChart.java 2017-03-09 14:44:09.334173408 -0800
+++ new/modules/javafx.controls/src/main/java/javafx/scene/chart/BarChart.java 2017-03-09 14:44:09.234173407 -0800
@@ -243,7 +243,7 @@
}
}
- /** @inheritDoc */
+ /** {@inheritDoc} */
@Override protected void dataItemChanged(Data item) {
double barVal;
double currentVal;
@@ -343,7 +343,7 @@
}
}
- /** @inheritDoc */
+ /** {@inheritDoc} */
@Override protected void layoutPlotChildren() {
double catSpace = categoryAxis.getCategorySpacing();
// calculate bar spacing
--- old/modules/javafx.controls/src/main/java/javafx/scene/chart/BubbleChart.java 2017-03-09 14:44:09.714173415 -0800
+++ new/modules/javafx.controls/src/main/java/javafx/scene/chart/BubbleChart.java 2017-03-09 14:44:09.594173413 -0800
@@ -90,7 +90,7 @@
return !(number instanceof Number) ? nullDefault : ((Number)number).doubleValue();
}
- /** @inheritDoc */
+ /** {@inheritDoc} */
@Override protected void layoutPlotChildren() {
// update bubble positions
for (int seriesIndex=0; seriesIndex < getDataSize(); seriesIndex++) {
@@ -167,7 +167,7 @@
}
}
- /** @inheritDoc */
+ /** {@inheritDoc} */
@Override protected void dataItemChanged(Data item) {
}
--- old/modules/javafx.controls/src/main/java/javafx/scene/chart/CategoryAxis.java 2017-03-09 14:44:10.074173422 -0800
+++ new/modules/javafx.controls/src/main/java/javafx/scene/chart/CategoryAxis.java 2017-03-09 14:44:09.966173420 -0800
@@ -199,6 +199,7 @@
* based on the charts data if autoRanging is true. If the application sets the categories
* then auto ranging is turned off. If there is an attempt to add duplicate entry into this list,
* an {@link IllegalArgumentException} is thrown.
+ * @param value the ordered list of categories plotted on this axis
*/
public final void setCategories(ObservableList value) {
categories.set(value);
--- old/modules/javafx.controls/src/main/java/javafx/scene/chart/Chart.java 2017-03-09 14:44:10.426173428 -0800
+++ new/modules/javafx.controls/src/main/java/javafx/scene/chart/Chart.java 2017-03-09 14:44:10.322173426 -0800
@@ -128,7 +128,7 @@
/**
* The side of the chart where the title is displayed
- * @default Side.TOP
+ * @defaultValue Side.TOP
*/
private ObjectProperty titleSide = new StyleableObjectProperty(Side.TOP) {
@Override protected void invalidated() {
@@ -309,6 +309,7 @@
/**
* This is used to check if any given animation should run. It returns true if animation is enabled and the node
* is visible and in a scene.
+ * @return true if animation is enabled and the node is visible and in a scene
*/
protected final boolean shouldAnimate(){
return getAnimated() && NodeHelper.isTreeShowing(this);
--- old/modules/javafx.controls/src/main/java/javafx/scene/chart/LineChart.java 2017-03-09 14:44:10.782173434 -0800
+++ new/modules/javafx.controls/src/main/java/javafx/scene/chart/LineChart.java 2017-03-09 14:44:10.678173432 -0800
@@ -187,7 +187,7 @@
// -------------- METHODS ------------------------------------------------------------------------------------------
- /** @inheritDoc */
+ /** {@inheritDoc} */
@Override protected void updateAxisRange() {
final Axis xa = getXAxis();
final Axis ya = getYAxis();
@@ -369,7 +369,7 @@
//Note: better animation here, point should move from old position to new position at center point between prev and next symbols
}
- /** @inheritDoc */
+ /** {@inheritDoc} */
@Override protected void dataItemChanged(Data item) {
}
@@ -447,7 +447,7 @@
}
}
- /** @inheritDoc */
+ /** {@inheritDoc} */
@Override protected void layoutPlotChildren() {
List constructedPath = new ArrayList<>(getDataSize());
for (int seriesIndex=0; seriesIndex < getDataSize(); seriesIndex++) {
@@ -491,7 +491,7 @@
}
}
}
- /** @inheritDoc */
+ /** {@inheritDoc} */
@Override void dataBeingRemovedIsAdded(Data item, Series series) {
if (fadeSymbolTransition != null) {
fadeSymbolTransition.setOnFinished(null);
@@ -515,7 +515,7 @@
}
XYValueMap.clear();
}
- /** @inheritDoc */
+ /** {@inheritDoc} */
@Override void seriesBeingRemovedIsAdded(Series series) {
if (seriesRemoveTimeline != null) {
seriesRemoveTimeline.setOnFinished(null);
--- old/modules/javafx.controls/src/main/java/javafx/scene/chart/PieChart.java 2017-03-09 14:44:11.158173441 -0800
+++ new/modules/javafx.controls/src/main/java/javafx/scene/chart/PieChart.java 2017-03-09 14:44:11.038173439 -0800
@@ -521,7 +521,7 @@
}
}
- /** @inheritDoc */
+ /** {@inheritDoc} */
@Override protected void layoutChartChildren(double top, double left, double contentWidth, double contentHeight) {
double total = 0.0;
for (Data item = begin; item != null; item = item.next) {
@@ -972,6 +972,7 @@
/**
* Returns the node that represents the pie slice. You can use this to
* add mouse event listeners etc.
+ * @return the node that represents the pie slice
*/
public Node getNode() {
return node.getValue();
--- old/modules/javafx.controls/src/main/java/javafx/scene/chart/ScatterChart.java 2017-03-09 14:44:11.514173447 -0800
+++ new/modules/javafx.controls/src/main/java/javafx/scene/chart/ScatterChart.java 2017-03-09 14:44:11.414173445 -0800
@@ -72,7 +72,7 @@
// -------------- METHODS ------------------------------------------------------------------------------------------
- /** @inheritDoc */
+ /** {@inheritDoc} */
@Override protected void dataItemAdded(Series series, int itemIndex, Data item) {
Node symbol = item.getNode();
// check if symbol has already been created
@@ -98,7 +98,7 @@
}
}
- /** @inheritDoc */
+ /** {@inheritDoc} */
@Override protected void dataItemRemoved(final Data item, final Series series) {
final Node symbol = item.getNode();
@@ -122,11 +122,11 @@
}
}
- /** @inheritDoc */
+ /** {@inheritDoc} */
@Override protected void dataItemChanged(Data item) {
}
- /** @inheritDoc */
+ /** {@inheritDoc} */
@Override protected void seriesAdded(Series series, int seriesIndex) {
// handle any data already in series
for (int j=0; j series) {
// remove all symbol nodes
if (shouldAnimate()) {
@@ -163,7 +163,7 @@
}
}
- /** @inheritDoc */
+ /** {@inheritDoc} */
@Override protected void layoutPlotChildren() {
// update symbol positions
for (int seriesIndex=0; seriesIndex < getDataSize(); seriesIndex++) {
--- old/modules/javafx.controls/src/main/java/javafx/scene/chart/StackedAreaChart.java 2017-03-09 14:44:11.870173453 -0800
+++ new/modules/javafx.controls/src/main/java/javafx/scene/chart/StackedAreaChart.java 2017-03-09 14:44:11.766173452 -0800
@@ -314,7 +314,7 @@
//Note: better animation here, point should move from old position to new position at center point between prev and next symbols
}
- /** @inheritDoc */
+ /** {@inheritDoc} */
@Override protected void dataItemChanged(Data item) {
}
@@ -396,7 +396,7 @@
}
}
- /** @inheritDoc */
+ /** {@inheritDoc} */
@Override protected void updateAxisRange() {
// This override is necessary to update axis range based on cumulative Y value for the
// Y axis instead of the normal way where max value in the data range is used.
@@ -497,7 +497,7 @@
}
- /** @inheritDoc */
+ /** {@inheritDoc} */
@Override protected void layoutPlotChildren() {
ArrayList> currentSeriesData = new ArrayList<>();
// AggregateData hold the data points of both the current and the previous series.
--- old/modules/javafx.controls/src/main/java/javafx/scene/chart/StackedBarChart.java 2017-03-09 14:44:12.226173460 -0800
+++ new/modules/javafx.controls/src/main/java/javafx/scene/chart/StackedBarChart.java 2017-03-09 14:44:12.122173458 -0800
@@ -233,7 +233,7 @@
}
}
- /** @inheritDoc */
+ /** {@inheritDoc} */
@Override protected void dataItemChanged(Data item) {
double barVal;
double currentVal;
@@ -266,7 +266,7 @@
}
}
- /** @inheritDoc */
+ /** {@inheritDoc} */
@Override protected void seriesAdded(Series series, int seriesIndex) {
// handle any data already in series
// create entry in the map
@@ -336,7 +336,7 @@
}
}
- /** @inheritDoc */
+ /** {@inheritDoc} */
@Override protected void updateAxisRange() {
// This override is necessary to update axis range based on cumulative Y value for the
// Y axis instead of the inherited way where the max value in the data range is used.
@@ -377,7 +377,7 @@
}
}
- /** @inheritDoc */
+ /** {@inheritDoc} */
@Override protected void layoutPlotChildren() {
double catSpace = categoryAxis.getCategorySpacing();
// calculate bar spacing
--- old/modules/javafx.controls/src/main/java/javafx/scene/chart/XYChart.java 2017-03-09 14:44:12.582173466 -0800
+++ new/modules/javafx.controls/src/main/java/javafx/scene/chart/XYChart.java 2017-03-09 14:44:12.482173464 -0800
@@ -172,11 +172,17 @@
// -------------- PUBLIC PROPERTIES --------------------------------------------------------------------------------
private final Axis xAxis;
- /** Get the X axis, by default it is along the bottom of the plot */
+ /**
+ * Get the X axis, by default it is along the bottom of the plot
+ * @return the X axis of the chart
+ */
public Axis getXAxis() { return xAxis; }
private final Axis yAxis;
- /** Get the Y axis, by default it is along the left of the plot */
+ /**
+ * Get the Y axis, by default it is along the left of the plot
+ * @return the Y axis of this chart
+ */
public Axis getYAxis() { return yAxis; }
/** XYCharts data */
@@ -612,7 +618,10 @@
*/
protected abstract void seriesRemoved(Series series);
- /** Called when each atomic change is made to the list of series for this chart */
+ /**
+ * Called when each atomic change is made to the list of series for this chart
+ * @param c The series that has been changed
+ */
protected void seriesChanged(Change extends Series> c) {}
/**
@@ -653,7 +662,7 @@
*/
protected abstract void layoutPlotChildren();
- /** @inheritDoc */
+ /** {@inheritDoc} */
@Override protected final void layoutChartChildren(double top, double left, double width, double height) {
if(getData() == null) return;
if (!rangeValid) {
@@ -963,12 +972,15 @@
* used by XYChart to animate the xValue from the old value to the new value. This is what you should plot
* in any custom XYChart implementations. Some XYChart chart implementations such as LineChart also use this
* to animate when data is added or removed.
+ * @param item The XYChart.Data item from which the current X axis data value is obtained
+ * @return The current displayed X data value
*/
protected final X getCurrentDisplayedXValue(Data item) { return item.getCurrentX(); }
/** Set the current displayed data value plotted on X axis.
*
* @param item The XYChart.Data item from which the current X axis data value is obtained.
+ * @param value The X axis data value
* @see #getCurrentDisplayedXValue
*/
protected final void setCurrentDisplayedXValue(Data item, X value) { item.setCurrentX(value); }
@@ -986,6 +998,8 @@
* used by XYChart to animate the yValue from the old value to the new value. This is what you should plot
* in any custom XYChart implementations. Some XYChart chart implementations such as LineChart also use this
* to animate when data is added or removed.
+ * @param item The XYChart.Data item from which the current Y axis data value is obtained
+ * @return The current displayed Y data value
*/
protected final Y getCurrentDisplayedYValue(Data item) { return item.getCurrentY(); }
@@ -993,6 +1007,7 @@
* Set the current displayed data value plotted on Y axis.
*
* @param item The XYChart.Data item from which the current Y axis data value is obtained.
+ * @param value The Y axis data value
* @see #getCurrentDisplayedYValue
*/
protected final void setCurrentDisplayedYValue(Data item, Y value) { item.setCurrentY(value); }
@@ -1009,6 +1024,8 @@
* The current displayed data extra value. This may be the same as extraValue or different. It is
* used by XYChart to animate the extraValue from the old value to the new value. This is what you should plot
* in any custom XYChart implementations.
+ * @param item The XYChart.Data item from which the current extra value is obtained
+ * @return The current extra value
*/
protected final Object getCurrentDisplayedExtraValue(Data item) { return item.getCurrentExtraValue(); }
@@ -1016,6 +1033,7 @@
* Set the current displayed data extra value.
*
* @param item The XYChart.Data item from which the current extra value is obtained.
+ * @param value The extra value
* @see #getCurrentDisplayedExtraValue
*/
protected final void setCurrentDisplayedExtraValue(Data item, Object value) { item.setCurrentExtraValue(value); }
@@ -1024,7 +1042,7 @@
* The current displayed extra value property.
*
* @param item The XYChart.Data item from which the current extra value property object is obtained.
- * @return ObjectProperty
Below is a table listing the existing Chart types and a brief
summary of their intended use.
-
+
Chart
@@ -124,107 +124,99 @@
javafx.scene.chart.XYChart.Series} objects. Each series contains
{@link javafx.scene.chart.XYChart.Data} objects.
-
-
// add data
-XYChart.Series<String,Number> series1 = new XYChart.Series<String,Number>();
-series1.setName("Data Series 1");
-series1.getData().add(new XYChart.Data<String,Number>(“2007”, 567));
-
-
+
{@code
+ // add data
+ XYChart.Series series1 = new XYChart.Series();
+ series1.setName("Data Series 1");
+ series1.getData().add(new XYChart.Data("2007", 567));
+}
We can define more series objects similarly. Following code
snippet shows how to create a BarChart with 3 categories and its X
and Y axis:
-
-
static String[] years = {"2007", "2008", "2009"};
-final CategoryAxis xAxis = new CategoryAxis();
-final NumberAxis yAxis = new NumberAxis();
-final BarChart<String,Number> bc = new BarChart<String,Number>(xAxis,yAxis);
-xAxis.setCategories(FXCollections.<String>observableArrayList(Arrays.asList(years)));
-bc.getData().addAll(series1, series2, series3);
-
-
+
{@code
+ static String[] years = {"2007", "2008", "2009"};
+ final CategoryAxis xAxis = new CategoryAxis();
+ final NumberAxis yAxis = new NumberAxis();
+ final BarChart bc = new BarChart(xAxis, yAxis);
+ xAxis.setCategories(FXCollections.observableArrayList(Arrays.asList(years)));
+ bc.getData().addAll(series1, series2, series3);
+}
JavaFX charts lends itself very well for real time or dynamic
Charting (like online stocks, web traffic etc) from live data sets.
Here is an example of a dynamic chart created with simulated data. A
{@link javafx.animation.Timeline} is used to simulate dynamic data
for stock price variations over time(hours).
-
-
private XYChart.Series<Number,Number> hourDataSeries;
-private NumberAxis xAxis;
-private Timeline animation;
-private double hours = 0;
-private double timeInHours = 0;
-private double prevY = 10;
-private double y = 10;
-
-// timeline to add new data every 60th of a second
-animation = new Timeline();
-animation.getKeyFrames().add(new KeyFrame(Duration.millis(1000 / 60), new EventHandler<ActionEvent>() {
- @Override public void handle(ActionEvent actionEvent) {
- // 6 minutes data per frame
-
-
for(int count=0; count < 6; count++) {
-
-
nextTime();
-plotTime();
-
-
}
-}
-
-
}));
-animation.setCycleCount(Animation.INDEFINITE);
-
-xAxis = new NumberAxis(0,24,3);
-
-
final NumberAxis yAxis = new NumberAxis(0,100,10);
- final LineChart<Number,Number> lc = new LineChart<Number,Number>(xAxis,yAxis);
-
- lc.setCreateSymbols(false);
- lc.setAnimated(false);
- lc.setLegendVisible(false);
- lc.setTitle("ACME Company Stock");
-
- xAxis.setLabel("Time");
- xAxis.setForceZeroInRange(false);
- yAxis.setLabel("Share Price");
- yAxis.setTickLabelFormatter(new NumberAxis.DefaultFormatter(yAxis,"$",null));
-
- hourDataSeries = new XYChart.Series<Number,Number>();
- hourDataSeries.setName("Hourly Data");
- hourDataSeries.getData().add(new XYChart.Data<Number,Number>(timeInHours,prevY));
- lc.getData().add(hourDataSeries);
-
- private void nextTime() {
- if (minutes == 59) {
- hours ++;
- minutes = 0;
- } else {
- minutes ++;
- }
- timeInHours = hours + ((1d/60d)*minutes);
- }
-
- private void plotTime() {
- if ((timeInHours % 1) == 0) {
- // change of hour
- double oldY = y;
- y = prevY - 10 + (Math.random()*20);
- prevY = oldY;
- while (y < 10 || y > 90) y = y - 10 + (Math.random()*20);
- hourDataSeries.getData().add(new XYChart.Data<Number, Number>(timeInHours, prevY));
- // after 25hours delete old data
- if (timeInHours > 25) hourDataSeries.getData().remove(0);
- // every hour after 24 move range 1 hour
- if (timeInHours > 24) {
- xAxis.setLowerBound(xAxis.getLowerBound()+1);
- xAxis.setUpperBound(xAxis.getUpperBound()+1);
- }
- }
- }
-
-
+
+ {@literal private XYChart.Series hourDataSeries;}
+ private NumberAxis xAxis;
+ private Timeline animation;
+ private double hours = 0;
+ private double timeInHours = 0;
+ private double prevY = 10;
+ private double y = 10;
+
+ // timeline to add new data every 60th of a second
+ animation = new Timeline();
+ {@literal animation.getKeyFrames().add(new KeyFrame(Duration.millis(1000 / 60), new EventHandler()} {
+ {@literal @Override public void handle(ActionEvent actionEvent)} {
+ // 6 minutes data per frame
+ {@literal for(int count = 0; count < 6; count++)} {
+ nextTime();
+ plotTime();
+ }
+ }
+ }));
+ animation.setCycleCount(Animation.INDEFINITE);
+ xAxis = new NumberAxis(0, 24, 3);
+ final NumberAxis yAxis = new NumberAxis(0, 100, 10);
+ {@literal final LineChart lc = new LineChart(xAxis, yAxis)};
+
+ lc.setCreateSymbols(false);
+ lc.setAnimated(false);
+ lc.setLegendVisible(false);
+ lc.setTitle("ACME Company Stock");
+
+ xAxis.setLabel("Time");
+ xAxis.setForceZeroInRange(false);
+ yAxis.setLabel("Share Price");
+ yAxis.setTickLabelFormatter(new NumberAxis.DefaultFormatter(yAxis, "$", null));
+
+ {@literal hourDataSeries = new XYChart.Series();}
+ hourDataSeries.setName("Hourly Data");
+ {@literal hourDataSeries.getData().add(new XYChart.Data(timeInHours, prevY));}
+ lc.getData().add(hourDataSeries);
+
+ private void nextTime() {
+ if (minutes == 59) {
+ hours++;
+ minutes = 0;
+ } else {
+ minutes++;
+ }
+ timeInHours = hours + ((1d/60d) * minutes);
+ }
+
+ private void plotTime() {
+ if ((timeInHours % 1) == 0) {
+ // change of hour
+ double oldY = y;
+ y = prevY - 10 + (Math.random() * 20);
+ prevY = oldY;
+ {@literal while (y < 10 || y > 90) y = y - 10 + (Math.random() * 20);}
+ {@literal hourDataSeries.getData().add(new XYChart.Data(timeInHours, prevY));}
+ // after 25hours delete old data
+ {@literal if (timeInHours > 25) hourDataSeries.getData().remove(0)};
+ // every hour after 24 move range 1 hour
+ {@literal if (timeInHours > 24)} {
+ xAxis.setLowerBound(xAxis.getLowerBound() + 1);
+ xAxis.setUpperBound(xAxis.getUpperBound() + 1);
+ }
+ }
+ }
+
+
The start method needs to call animation,.play() to start the
simulated dynamic chart.
Please refer to javafx.scene.control package documentation on CSS
@@ -235,8 +227,5 @@