Class CjDataset

java.lang.Object
com.oorian.chartjs.CjDataset
All Implemented Interfaces:
com.oorian.json.Jsonable

public class CjDataset extends Object implements 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 Details

    • CjDataset

      public CjDataset()
      Creates an empty dataset.
    • CjDataset

      public CjDataset(String label)
      Creates a dataset with a label.
      Parameters:
      label - The dataset label
  • Method Details

    • setLabel

      public CjDataset setLabel(String label)
      Sets the dataset label.
      Parameters:
      label - The label displayed in the legend
      Returns:
      This instance for method chaining
    • getLabel

      public String getLabel()
      Gets the dataset label.
      Returns:
      The label
    • setData

      public CjDataset setData(Number... values)
      Sets the data values.
      Parameters:
      values - The numeric data values
      Returns:
      This instance for method chaining
    • setData

      public CjDataset setData(List<Number> values)
      Sets the data values from a list.
      Parameters:
      values - The numeric data values
      Returns:
      This instance for method chaining
    • getData

      public List<Number> getData()
      Gets the data values.
      Returns:
      The data list
    • setDataPoints

      public CjDataset setDataPoints(CjDataPoint... points)
      Sets data points for scatter/bubble charts.
      Parameters:
      points - The data points
      Returns:
      This instance for method chaining
    • setDataPoints

      public CjDataset setDataPoints(List<CjDataPoint> points)
      Sets data points from a list.
      Parameters:
      points - The data points
      Returns:
      This instance for method chaining
    • getDataPoints

      public List<CjDataPoint> getDataPoints()
      Gets the data points.
      Returns:
      The data points list
    • addData

      public CjDataset addData(Number value)
      Adds a single data value.
      Parameters:
      value - The value to add
      Returns:
      This instance for method chaining
    • addData

      public CjDataset addData(CjDataPoint point)
      Adds a single data point.
      Parameters:
      point - The data point to add
      Returns:
      This instance for method chaining
    • setBackgroundColor

      public CjDataset setBackgroundColor(String... colors)
      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

      public CjDataset setBackgroundColors(String... colors)
      Sets individual background colors for each data point.
      Parameters:
      colors - The CSS color values
      Returns:
      This instance for method chaining
    • setBackgroundColors

      public CjDataset setBackgroundColors(List<String> colors)
      Sets individual background colors from a list.
      Parameters:
      colors - The CSS color values
      Returns:
      This instance for method chaining
    • setBorderColor

      public CjDataset setBorderColor(String color)
      Sets a single border color.
      Parameters:
      color - The CSS color value
      Returns:
      This instance for method chaining
    • setBorderColors

      public CjDataset setBorderColors(String... colors)
      Sets individual border colors for each data point.
      Parameters:
      colors - The CSS color values
      Returns:
      This instance for method chaining
    • setBorderWidth

      public CjDataset setBorderWidth(int width)
      Sets the border width.
      Parameters:
      width - The border width in pixels
      Returns:
      This instance for method chaining
    • setFill

      public CjDataset setFill(boolean fill)
      Sets whether to fill the area under the line.
      Parameters:
      fill - True to fill, false otherwise
      Returns:
      This instance for method chaining
    • setFill

      public CjDataset setFill(FillMode mode)
      Sets the fill mode for the area chart.
      Parameters:
      mode - The fill mode
      Returns:
      This instance for method chaining
    • setTension

      public CjDataset setTension(double tension)
      Sets the bezier curve tension (smoothness).
      Parameters:
      tension - 0 for straight lines, 0.4 for smooth curves
      Returns:
      This instance for method chaining
    • setStepped

      public CjDataset setStepped(boolean stepped)
      Sets whether to use stepped lines.
      Parameters:
      stepped - True for stepped lines
      Returns:
      This instance for method chaining
    • setPointStyle

      public CjDataset setPointStyle(PointStyle style)
      Sets the point style.
      Parameters:
      style - The point style
      Returns:
      This instance for method chaining
    • setPointRadius

      public CjDataset setPointRadius(int radius)
      Sets the point radius.
      Parameters:
      radius - The radius in pixels
      Returns:
      This instance for method chaining
    • setPointHoverRadius

      public CjDataset setPointHoverRadius(int radius)
      Sets the point hover radius.
      Parameters:
      radius - The hover radius in pixels
      Returns:
      This instance for method chaining
    • setPointBackgroundColor

      public CjDataset setPointBackgroundColor(String color)
      Sets the point background color.
      Parameters:
      color - The CSS color value
      Returns:
      This instance for method chaining
    • setPointBorderColor

      public CjDataset setPointBorderColor(String color)
      Sets the point border color.
      Parameters:
      color - The CSS color value
      Returns:
      This instance for method chaining
    • setShowLine

      public CjDataset setShowLine(boolean showLine)
      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

      public CjDataset setBarPercentage(double percentage)
      Sets the bar percentage (width relative to category).
      Parameters:
      percentage - 0.0 to 1.0
      Returns:
      This instance for method chaining
    • setCategoryPercentage

      public CjDataset setCategoryPercentage(double percentage)
      Sets the category percentage.
      Parameters:
      percentage - 0.0 to 1.0
      Returns:
      This instance for method chaining
    • setBarThickness

      public CjDataset setBarThickness(int thickness)
      Sets the bar thickness in pixels.
      Parameters:
      thickness - The thickness in pixels
      Returns:
      This instance for method chaining
    • setMaxBarThickness

      public CjDataset setMaxBarThickness(int thickness)
      Sets the maximum bar thickness.
      Parameters:
      thickness - The maximum thickness in pixels
      Returns:
      This instance for method chaining
    • setBorderRadius

      public CjDataset setBorderRadius(int radius)
      Sets the border radius for bars.
      Parameters:
      radius - The radius in pixels
      Returns:
      This instance for method chaining
    • setBorderSkipped

      public CjDataset setBorderSkipped(String skip)
      Sets which border to skip.
      Parameters:
      skip - "start", "end", "middle", "bottom", "left", "top", "right", or false
      Returns:
      This instance for method chaining
    • setCutout

      public CjDataset setCutout(String cutout)
      Sets the cutout percentage for doughnut charts.
      Parameters:
      cutout - e.g., "50%" for a doughnut
      Returns:
      This instance for method chaining
    • setCircumference

      public CjDataset setCircumference(int degrees)
      Sets the arc circumference in degrees.
      Parameters:
      degrees - The degrees (360 for full circle)
      Returns:
      This instance for method chaining
    • setRotation

      public CjDataset setRotation(int degrees)
      Sets the rotation offset in degrees.
      Parameters:
      degrees - The rotation offset
      Returns:
      This instance for method chaining
    • setSpacing

      public CjDataset setSpacing(int pixels)
      Sets the spacing between arcs.
      Parameters:
      pixels - The spacing in pixels
      Returns:
      This instance for method chaining
    • setOffset

      public CjDataset setOffset(int pixels)
      Sets the offset for all arcs.
      Parameters:
      pixels - The offset in pixels
      Returns:
      This instance for method chaining
    • setHoverOffset

      public CjDataset setHoverOffset(int pixels)
      Sets the hover offset for arcs.
      Parameters:
      pixels - The hover offset in pixels
      Returns:
      This instance for method chaining
    • setHidden

      public CjDataset setHidden(boolean hidden)
      Sets whether this dataset is hidden.
      Parameters:
      hidden - True to hide
      Returns:
      This instance for method chaining
    • setOrder

      public CjDataset setOrder(int order)
      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:
      initFromJson in interface com.oorian.json.Jsonable
    • toJsonValue

      public com.oorian.json.JsonValue toJsonValue()
      Specified by:
      toJsonValue in interface com.oorian.json.Jsonable
    • line

      public static CjDataset line(String label, Number... values)
      Creates a line chart dataset.
      Parameters:
      label - The dataset label
      values - The data values
      Returns:
      A new CjDataset
    • bar

      public static CjDataset bar(String label, Number... values)
      Creates a bar chart dataset.
      Parameters:
      label - The dataset label
      values - The data values
      Returns:
      A new CjDataset
    • pie

      public static CjDataset pie(String label, Number... values)
      Creates a pie chart dataset.
      Parameters:
      label - The dataset label
      values - The data values
      Returns:
      A new CjDataset
    • scatter

      public static CjDataset scatter(String label, CjDataPoint... points)
      Creates a scatter chart dataset.
      Parameters:
      label - The dataset label
      points - The data points
      Returns:
      A new CjDataset