com.vaadin.flow.component.charts.model.
Class DataSeries
- java.lang.Object
-
- com.vaadin.flow.component.charts.model.AbstractConfigurationObject
-
- com.vaadin.flow.component.charts.model.AbstractSeries
-
- com.vaadin.flow.component.charts.model.DataSeries
-
All Implemented Interfaces:
Direct Known Subclasses:
public class DataSeries extends AbstractSeries
An array of data points to be displayed in a chart.
The class uses
DataSeriesItem
to represent individual data points. The class also has various helper methods and constructors that allow passing data as arrays or lists.See Also:
-
-
Constructor Summary
Constructors Constructor Description DataSeries()
Constructs an empty
DataSeries
.DataSeries(DataSeriesItem... items)
Constructs a new DataSeries with the given items.
DataSeries(String name)
Constructs a new DataSeries instance with the given name.
DataSeries(String[] categories, Number[] ys)
Constructs a DataSeries instance containing the given category name, Y value pairs.
DataSeries(List<DataSeriesItem> items)
Constructs a new DataSeries instance with the given items.
-
Method Summary
All Methods Modifier and Type Method Description void
add(DataSeriesItem item)
Adds a data item and immediately updates the chart if it already has been drawn.
void
add(DataSeriesItem item, boolean updateChartImmediately, boolean shift)
Adds a data item and immediately sends an update to the chart if so specified.
void
addData(Number[][] entries)
Adds a list of (x,y) data pairs e.g.
void
addItemWithDrilldown(DataSeriesItem item)
Adds a new item to the series data and enables drilldown for it.
void
addItemWithDrilldown(DataSeriesItem item, Series series)
Adds a new item to the series data.
void
clear()
Removes all items from the series.
DataSeriesItem
get(int index)
Returns
DataSeriesItem
at given indexDataSeriesItem
get(String name)
List<DataSeriesItem>
getData()
Return an unmodifiable list of the data items in this series.
void
remove(DataSeriesItem item)
Removes a given item and immediately removes it from the chart.
void
setData(Number... values)
Sets the data entries, first clearing the old ones.
void
setData(String[] categoryNames, Number[] values)
Sets the data entries, first clearing the old ones.
void
setData(String[] categoryNames, Number[] values, Color[] colors)
Sets the data entries, first clearing the old ones.
void
setData(List<DataSeriesItem> data)
Sets the data to the provided list of data items.
void
setItemSliced(int index, boolean sliced)
Sets a new sliced value to the item with the specified index
void
setItemSliced(int index, boolean sliced, boolean redraw)
Sets a new sliced value to the item with the specified index
void
setItemSliced(int index, boolean sliced, boolean redraw, boolean animation)
Sets a new sliced value to the item with the specified index
int
size()
void
update(DataSeriesItem item)
Triggers an update of the chart for the specified data item.
-
Methods inherited from class com.vaadin.flow.component.charts.model.AbstractSeries
getColorAxis, getConfiguration, getId, getName, getPlotOptions, getStack, getxAxis, getyAxis, isVisible, setColorAxis, setConfiguration, setId, setName, setPlotOptions, setStack, setVisible, setVisible, setxAxis, setyAxis, setyAxis, updateSeries
-
-
-
-
Constructor Detail
-
DataSeries
public DataSeries()
Constructs an empty
DataSeries
. Developers should then populate the series with various addData and setData methods.
-
DataSeries
public DataSeries(String[] categories, Number[] ys)
Constructs a DataSeries instance containing the given category name, Y value pairs.
Parameters:
categories
-ys
-
-
DataSeries
public DataSeries(String name)
Constructs a new DataSeries instance with the given name.
-
DataSeries
public DataSeries(List<DataSeriesItem> items)
Constructs a new DataSeries instance with the given items.
Parameters:
items
- items to be contained in the constructed DataSeries
-
DataSeries
public DataSeries(DataSeriesItem... items)
Constructs a new DataSeries with the given items.
Parameters:
items
- items to be contained in the constructed DataSeries
-
-
Method Detail
-
addData
public void addData(Number[][] entries)
Adds a list of (x,y) data pairs e.g.
[[0, 15], [10, -50], [20, -56.5]...
could be inserted as followsnew Number[][] { { 0, 15 }, { 10, -50 }, { 20, -56.5 }
Parameters:
entries
- An array of Numbers representing the (x,y) data pairs.
-
setData
public void setData(String[] categoryNames, Number[] values)
Sets the data entries, first clearing the old ones. Uses the given category names and numeric values. The categoryNames and values arrays must be of equal length.
Parameters:
categoryNames
- An array of the category names.values
- An array of the values for each category in the categoryNames parameter.
-
setData
public void setData(String[] categoryNames, Number[] values, Color[] colors)
Sets the data entries, first clearing the old ones. Uses the given category names, numeric values, and colors. The categoryNames, values and colors arrays must be of equal length.
Parameters:
categoryNames
- An array of the category names.values
- An array of the values for each category in the categoryNames parameter.colors
- An array of colors for each category name, value pair.
-
setData
public void setData(Number... values)
Sets the data entries, first clearing the old ones. Uses the same numeric value for names (value.toString) and Y-values.
Parameters:
values
-
-
setData
public void setData(List<DataSeriesItem> data)
Sets the data to the provided list of data items.
Parameters:
data
-
-
get
public DataSeriesItem get(String name)
Parameters:
name
- The name of the data item to find.Returns:
The first
DataSeriesItem
identified by the specified name. Returns null if no matching item is found.
-
add
public void add(DataSeriesItem item)
Adds a data item and immediately updates the chart if it already has been drawn. If the chart has not yet been drawn, all items added will be added to the chart when the chart is drawn.
Parameters:
item
- the data item to be addedSee Also:
-
addItemWithDrilldown
public void addItemWithDrilldown(DataSeriesItem item, Series series)
Adds a new item to the series data. And sets the series as its drilldown. Used for eager loading drilldown. Series must have an id. The remaining drilldown configurations can be set in
Configuration.getDrilldown()
Parameters:
item
-series
-
-
addItemWithDrilldown
public void addItemWithDrilldown(DataSeriesItem item)
Adds a new item to the series data and enables drilldown for it. Used for lazy loading drilldown. Using async drilldown requires setting
Chart.setDrilldownCallback(DrilldownCallback)
to return aSeries
when drilldown is done. The remaining drilldown configurations can be set inConfiguration.getDrilldown()
Parameters:
item
-
-
add
public void add(DataSeriesItem item, boolean updateChartImmediately, boolean shift)
Adds a data item and immediately sends an update to the chart if so specified. Immediately updating the chart causes it to dynamically add the data point.
This method is useful if you want to add many items without a client/server round-trip for each item added. Do this by setting the updateChartImmediately parameter to false.
Parameters:
item
- The item to add.updateChartImmediately
- Updates the chart immediately if true.shift
- If true, the first item from the series is removed. Handy if dynamically adjusting adding points and fixed amount of points should be kept visible.
-
remove
public void remove(DataSeriesItem item)
Removes a given item and immediately removes it from the chart.
Parameters:
item
- The item to remove.
-
getData
public List<DataSeriesItem> getData()
Return an unmodifiable list of the data items in this series.
-
update
public void update(DataSeriesItem item)
Triggers an update of the chart for the specified data item. Only the Y value of the DataSeriesItem is updated.
Parameters:
item
- The item to update.
-
get
public DataSeriesItem get(int index)
Returns
DataSeriesItem
at given indexParameters:
index
-Returns:
the Item
Throws:
IndexOutOfBoundsException
- if data series don't have item at given index
-
size
public int size()
Returns:
the number of data items in the series
-
clear
public void clear()
Removes all items from the series.
-
setItemSliced
public void setItemSliced(int index, boolean sliced)
Sets a new sliced value to the item with the specified index
Parameters:
index
- Index of the Item to modifysliced
- When true, the point is sliced out. When false, the point is set in. When null the sliced state is toggled
-
setItemSliced
public void setItemSliced(int index, boolean sliced, boolean redraw)
Sets a new sliced value to the item with the specified index
Parameters:
index
- Index of the Item to modifysliced
- When true, the point is sliced out. When false, the point is set in. When null the sliced state is toggledredraw
- Whether to redraw the chart after the point is altered.
-
setItemSliced
public void setItemSliced(int index, boolean sliced, boolean redraw, boolean animation)
Sets a new sliced value to the item with the specified index
Parameters:
index
- Index of the Item to modifysliced
- When true, the point is sliced out. When false, the point is set in. When null the sliced state is toggledredraw
- Whether to redraw the chart after the point is altered.animation
- When true, the move will be animated with default animation options
-
-