Package com.oorian.chartjs
Class CjDataset
java.lang.Object
com.oorian.chartjs.CjDataset
- All Implemented Interfaces:
com.oorian.json.Jsonable
Represents a dataset for Chart.js charts.
A dataset contains the data values and styling options for a single data series in a chart. Uses typed fields for all configuration options.
Usage:
// Quick creation with static factory
CjDataset dataset = CjDataset.line("Sales", 10, 20, 30, 40);
// Full configuration with fluent API
CjDataset dataset = new CjDataset("Revenue")
.setData(100, 200, 150, 300)
.setBackgroundColor("rgba(75, 192, 192, 0.2)")
.setBorderColor("rgb(75, 192, 192)")
.setBorderWidth(2)
.setTension(0.4);
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddData(CjDataPoint point) Adds a single data point.Adds a single data value.static CjDatasetCreates a bar chart dataset.getData()Gets the data values.Gets the data points.getLabel()Gets the dataset label.voidinitFromJson(com.oorian.json.JsonValue json) static CjDatasetCreates a line chart dataset.static CjDatasetCreates a pie chart dataset.static CjDatasetscatter(String label, CjDataPoint... points) Creates a scatter chart dataset.setBackgroundColor(String... colors) Sets background color(s).setBackgroundColors(String... colors) Sets individual background colors for each data point.setBackgroundColors(List<String> colors) Sets individual background colors from a list.setBarPercentage(double percentage) Sets the bar percentage (width relative to category).setBarThickness(int thickness) Sets the bar thickness in pixels.setBorderColor(String color) Sets a single border color.setBorderColors(String... colors) Sets individual border colors for each data point.setBorderRadius(int radius) Sets the border radius for bars.setBorderSkipped(String skip) Sets which border to skip.setBorderWidth(int width) Sets the border width.setCategoryPercentage(double percentage) Sets the category percentage.setCircumference(int degrees) Sets the arc circumference in degrees.Sets the cutout percentage for doughnut charts.Sets the data values.Sets the data values from a list.setDataPoints(CjDataPoint... points) Sets data points for scatter/bubble charts.setDataPoints(List<CjDataPoint> points) Sets data points from a list.setFill(boolean fill) Sets whether to fill the area under the line.Sets the fill mode for the area chart.setHidden(boolean hidden) Sets whether this dataset is hidden.setHoverOffset(int pixels) Sets the hover offset for arcs.Sets the dataset label.setMaxBarThickness(int thickness) Sets the maximum bar thickness.setOffset(int pixels) Sets the offset for all arcs.setOrder(int order) Sets the drawing order for this dataset.setPointBackgroundColor(String color) Sets the point background color.setPointBorderColor(String color) Sets the point border color.setPointHoverRadius(int radius) Sets the point hover radius.setPointRadius(int radius) Sets the point radius.setPointStyle(PointStyle style) Sets the point style.setRotation(int degrees) Sets the rotation offset in degrees.setShowLine(boolean showLine) Sets whether to show the line (for scatter charts with lines).setSpacing(int pixels) Sets the spacing between arcs.setStepped(boolean stepped) Sets whether to use stepped lines.setTension(double tension) Sets the bezier curve tension (smoothness).com.oorian.json.JsonValueMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.oorian.json.Jsonable
initFromJson, initFromJson, toJsonString
-
Constructor Details
-
CjDataset
public CjDataset()Creates an empty dataset. -
CjDataset
Creates a dataset with a label.- Parameters:
label- The dataset label
-
-
Method Details
-
setLabel
Sets the dataset label.- Parameters:
label- The label displayed in the legend- Returns:
- This instance for method chaining
-
getLabel
Gets the dataset label.- Returns:
- The label
-
setData
Sets the data values.- Parameters:
values- The numeric data values- Returns:
- This instance for method chaining
-
setData
Sets the data values from a list.- Parameters:
values- The numeric data values- Returns:
- This instance for method chaining
-
getData
Gets the data values.- Returns:
- The data list
-
setDataPoints
Sets data points for scatter/bubble charts.- Parameters:
points- The data points- Returns:
- This instance for method chaining
-
setDataPoints
Sets data points from a list.- Parameters:
points- The data points- Returns:
- This instance for method chaining
-
getDataPoints
Gets the data points.- Returns:
- The data points list
-
addData
Adds a single data value.- Parameters:
value- The value to add- Returns:
- This instance for method chaining
-
addData
Adds a single data point.- Parameters:
point- The data point to add- Returns:
- This instance for method chaining
-
setBackgroundColor
Sets background color(s). If a single color is provided, it applies to all data points. If multiple colors are provided, each applies to the corresponding data point.- Parameters:
colors- The CSS color value(s)- Returns:
- This instance for method chaining
-
setBackgroundColors
Sets individual background colors for each data point.- Parameters:
colors- The CSS color values- Returns:
- This instance for method chaining
-
setBackgroundColors
Sets individual background colors from a list.- Parameters:
colors- The CSS color values- Returns:
- This instance for method chaining
-
setBorderColor
Sets a single border color.- Parameters:
color- The CSS color value- Returns:
- This instance for method chaining
-
setBorderColors
Sets individual border colors for each data point.- Parameters:
colors- The CSS color values- Returns:
- This instance for method chaining
-
setBorderWidth
Sets the border width.- Parameters:
width- The border width in pixels- Returns:
- This instance for method chaining
-
setFill
Sets whether to fill the area under the line.- Parameters:
fill- True to fill, false otherwise- Returns:
- This instance for method chaining
-
setFill
Sets the fill mode for the area chart.- Parameters:
mode- The fill mode- Returns:
- This instance for method chaining
-
setTension
Sets the bezier curve tension (smoothness).- Parameters:
tension- 0 for straight lines, 0.4 for smooth curves- Returns:
- This instance for method chaining
-
setStepped
Sets whether to use stepped lines.- Parameters:
stepped- True for stepped lines- Returns:
- This instance for method chaining
-
setPointStyle
Sets the point style.- Parameters:
style- The point style- Returns:
- This instance for method chaining
-
setPointRadius
Sets the point radius.- Parameters:
radius- The radius in pixels- Returns:
- This instance for method chaining
-
setPointHoverRadius
Sets the point hover radius.- Parameters:
radius- The hover radius in pixels- Returns:
- This instance for method chaining
-
setPointBackgroundColor
Sets the point background color.- Parameters:
color- The CSS color value- Returns:
- This instance for method chaining
-
setPointBorderColor
Sets the point border color.- Parameters:
color- The CSS color value- Returns:
- This instance for method chaining
-
setShowLine
Sets whether to show the line (for scatter charts with lines).- Parameters:
showLine- True to show the line- Returns:
- This instance for method chaining
-
setBarPercentage
Sets the bar percentage (width relative to category).- Parameters:
percentage- 0.0 to 1.0- Returns:
- This instance for method chaining
-
setCategoryPercentage
Sets the category percentage.- Parameters:
percentage- 0.0 to 1.0- Returns:
- This instance for method chaining
-
setBarThickness
Sets the bar thickness in pixels.- Parameters:
thickness- The thickness in pixels- Returns:
- This instance for method chaining
-
setMaxBarThickness
Sets the maximum bar thickness.- Parameters:
thickness- The maximum thickness in pixels- Returns:
- This instance for method chaining
-
setBorderRadius
Sets the border radius for bars.- Parameters:
radius- The radius in pixels- Returns:
- This instance for method chaining
-
setBorderSkipped
Sets which border to skip.- Parameters:
skip- "start", "end", "middle", "bottom", "left", "top", "right", or false- Returns:
- This instance for method chaining
-
setCutout
Sets the cutout percentage for doughnut charts.- Parameters:
cutout- e.g., "50%" for a doughnut- Returns:
- This instance for method chaining
-
setCircumference
Sets the arc circumference in degrees.- Parameters:
degrees- The degrees (360 for full circle)- Returns:
- This instance for method chaining
-
setRotation
Sets the rotation offset in degrees.- Parameters:
degrees- The rotation offset- Returns:
- This instance for method chaining
-
setSpacing
Sets the spacing between arcs.- Parameters:
pixels- The spacing in pixels- Returns:
- This instance for method chaining
-
setOffset
Sets the offset for all arcs.- Parameters:
pixels- The offset in pixels- Returns:
- This instance for method chaining
-
setHoverOffset
Sets the hover offset for arcs.- Parameters:
pixels- The hover offset in pixels- Returns:
- This instance for method chaining
-
setHidden
Sets whether this dataset is hidden.- Parameters:
hidden- True to hide- Returns:
- This instance for method chaining
-
setOrder
Sets the drawing order for this dataset.- Parameters:
order- Lower numbers are drawn first- Returns:
- This instance for method chaining
-
initFromJson
public void initFromJson(com.oorian.json.JsonValue json) - Specified by:
initFromJsonin interfacecom.oorian.json.Jsonable
-
toJsonValue
public com.oorian.json.JsonValue toJsonValue()- Specified by:
toJsonValuein interfacecom.oorian.json.Jsonable
-
line
Creates a line chart dataset.- Parameters:
label- The dataset labelvalues- The data values- Returns:
- A new CjDataset
-
bar
Creates a bar chart dataset.- Parameters:
label- The dataset labelvalues- The data values- Returns:
- A new CjDataset
-
pie
Creates a pie chart dataset.- Parameters:
label- The dataset labelvalues- The data values- Returns:
- A new CjDataset
-
scatter
Creates a scatter chart dataset.- Parameters:
label- The dataset labelpoints- The data points- Returns:
- A new CjDataset
-