Class CjChart

java.lang.Object
com.oorian.html.Element<CjChart>
com.oorian.chartjs.ChartJsComponent<CjChart>
com.oorian.chartjs.CjChart
Direct Known Subclasses:
CjBarChart, CjBubbleChart, CjDoughnutChart, CjLineChart, CjPieChart, CjPolarAreaChart, CjRadarChart, CjScatterChart

public class CjChart extends ChartJsComponent<CjChart>
Main Chart.js chart component for the Oorian framework.

CjChart provides a fluent API for creating and configuring Chart.js charts. It supports all major chart types including line, bar, pie, doughnut, radar, polar area, scatter, and bubble charts.

Uses typed fields for all configuration. JsonObject is only used in the final serialization for rendering.

Basic Usage:


 CjChart chart = new CjChart(ChartType.LINE)
     .setLabels("Jan", "Feb", "Mar", "Apr", "May")
     .addDataset(new CjDataset("Sales")
         .setData(10, 20, 15, 25, 30)
         .setBorderColor("rgb(75, 192, 192)")
         .setTension(0.4))
     .setTitle("Monthly Sales")
     .setLegendPosition(LegendPosition.BOTTOM);

 container.addElement(chart);
 
See Also:
  • Constructor Details

    • CjChart

      public CjChart()
      Creates a new chart with the default type (line).
    • CjChart

      public CjChart(ChartType type)
      Creates a new chart with the specified type.
      Parameters:
      type - The chart type
  • Method Details

    • setChartType

      public CjChart setChartType(ChartType type)
      Sets the chart type.
      Parameters:
      type - The chart type
      Returns:
      This instance for method chaining
    • setChartType

      public CjChart setChartType(String type)
      Sets the chart type by string value.
      Parameters:
      type - The chart type string (e.g., "line", "bar", "pie")
      Returns:
      This instance for method chaining
    • setLabels

      public CjChart setLabels(String... labelValues)
      Sets the chart labels (x-axis categories).
      Parameters:
      labelValues - The label values
      Returns:
      This instance for method chaining
    • setLabels

      public CjChart setLabels(List<String> labelValues)
      Sets the chart labels from a list.
      Parameters:
      labelValues - The label values
      Returns:
      This instance for method chaining
    • getLabels

      public List<String> getLabels()
      Gets the chart labels.
      Returns:
      The labels list
    • addDataset

      public CjChart addDataset(CjDataset dataset)
      Adds a dataset to the chart.
      Parameters:
      dataset - The dataset to add
      Returns:
      This instance for method chaining
    • setDatasets

      public CjChart setDatasets(List<CjDataset> datasetList)
      Sets all datasets at once.
      Parameters:
      datasetList - The list of datasets
      Returns:
      This instance for method chaining
    • getDatasets

      public List<CjDataset> getDatasets()
      Gets the datasets.
      Returns:
      The datasets list
    • setData

      public CjChart setData(String label, Number... values)
      Convenience method to quickly add data with a label.
      Parameters:
      label - The dataset label
      values - The data values
      Returns:
      This instance for method chaining
    • setData

      public CjChart setData(String label, List<Number> values)
      Convenience method to quickly add data from a list.
      Parameters:
      label - The dataset label
      values - The data values
      Returns:
      This instance for method chaining
    • setOptions

      public CjChart setOptions(CjChartOptions options)
      Sets the options configuration directly.
      Parameters:
      options - The options configuration
      Returns:
      This instance for method chaining
    • setScales

      public CjChart setScales(CjScales scales)
      Sets the scales configuration.
      Parameters:
      scales - The scales configuration
      Returns:
      This instance for method chaining
    • getScales

      public CjScales getScales()
      Gets the scales configuration.
      Returns:
      The scales config, or null if not set
    • setXAxisType

      public CjChart setXAxisType(ScaleType type)
      Sets the X-axis scale type.
      Parameters:
      type - The scale type
      Returns:
      This instance for method chaining
    • setYAxisType

      public CjChart setYAxisType(ScaleType type)
      Sets the Y-axis scale type.
      Parameters:
      type - The scale type
      Returns:
      This instance for method chaining
    • setXAxisMin

      public CjChart setXAxisMin(Number min)
      Sets the X-axis minimum value.
      Parameters:
      min - The minimum value
      Returns:
      This instance for method chaining
    • setXAxisMax

      public CjChart setXAxisMax(Number max)
      Sets the X-axis maximum value.
      Parameters:
      max - The maximum value
      Returns:
      This instance for method chaining
    • setYAxisMin

      public CjChart setYAxisMin(Number min)
      Sets the Y-axis minimum value.
      Parameters:
      min - The minimum value
      Returns:
      This instance for method chaining
    • setYAxisMax

      public CjChart setYAxisMax(Number max)
      Sets the Y-axis maximum value.
      Parameters:
      max - The maximum value
      Returns:
      This instance for method chaining
    • setXAxisTitle

      public CjChart setXAxisTitle(String title)
      Sets the X-axis title.
      Parameters:
      title - The axis title
      Returns:
      This instance for method chaining
    • setYAxisTitle

      public CjChart setYAxisTitle(String title)
      Sets the Y-axis title.
      Parameters:
      title - The axis title
      Returns:
      This instance for method chaining
    • setYAxisBeginAtZero

      public CjChart setYAxisBeginAtZero(boolean beginAtZero)
      Sets whether the Y-axis begins at zero.
      Parameters:
      beginAtZero - True to begin at zero
      Returns:
      This instance for method chaining
    • setIndexAxis

      public CjChart setIndexAxis(IndexAxis axis)
      Sets the index axis for horizontal bar charts.
      Parameters:
      axis - The index axis (X for vertical, Y for horizontal)
      Returns:
      This instance for method chaining
    • setPlugins

      public CjChart setPlugins(CjPlugins plugins)
      Sets the plugins configuration.
      Parameters:
      plugins - The plugins configuration
      Returns:
      This instance for method chaining
    • getPlugins

      public CjPlugins getPlugins()
      Gets the plugins configuration.
      Returns:
      The plugins config, or null if not set
    • setTitle

      public CjChart setTitle(String title)
      Sets the chart title.
      Parameters:
      title - The chart title
      Returns:
      This instance for method chaining
    • setSubtitle

      public CjChart setSubtitle(String subtitle)
      Sets the chart subtitle.
      Parameters:
      subtitle - The chart subtitle
      Returns:
      This instance for method chaining
    • setLegendPosition

      public CjChart setLegendPosition(LegendPosition position)
      Sets the legend position.
      Parameters:
      position - The legend position
      Returns:
      This instance for method chaining
    • setLegendVisible

      public CjChart setLegendVisible(boolean visible)
      Sets whether the legend is visible.
      Parameters:
      visible - True to show the legend
      Returns:
      This instance for method chaining
    • setTooltipEnabled

      public CjChart setTooltipEnabled(boolean enabled)
      Sets whether tooltips are enabled.
      Parameters:
      enabled - True to enable tooltips
      Returns:
      This instance for method chaining
    • setResponsive

      public CjChart setResponsive(boolean responsive)
      Sets whether the chart is responsive.
      Parameters:
      responsive - True for responsive sizing
      Returns:
      This instance for method chaining
    • setMaintainAspectRatio

      public CjChart setMaintainAspectRatio(boolean maintain)
      Sets whether to maintain aspect ratio.
      Parameters:
      maintain - True to maintain aspect ratio
      Returns:
      This instance for method chaining
    • setAspectRatio

      public CjChart setAspectRatio(double ratio)
      Sets the aspect ratio.
      Parameters:
      ratio - The aspect ratio (width/height)
      Returns:
      This instance for method chaining
    • setInteractionMode

      public CjChart setInteractionMode(InteractionMode mode)
      Sets the interaction mode.
      Parameters:
      mode - The interaction mode
      Returns:
      This instance for method chaining
    • setInteractionIntersect

      public CjChart setInteractionIntersect(boolean intersect)
      Sets whether interaction requires intersecting the element.
      Parameters:
      intersect - True to require intersection
      Returns:
      This instance for method chaining
    • setHoverMode

      public CjChart setHoverMode(InteractionMode mode)
      Sets the hover mode.
      Parameters:
      mode - The hover mode
      Returns:
      This instance for method chaining
    • setAnimationDuration

      public CjChart setAnimationDuration(int milliseconds)
      Sets the animation duration.
      Parameters:
      milliseconds - Duration in milliseconds
      Returns:
      This instance for method chaining
    • setAnimationsEnabled

      public CjChart setAnimationsEnabled(boolean enabled)
      Sets whether animations are enabled.
      Parameters:
      enabled - True to enable animations
      Returns:
      This instance for method chaining
    • updateChart

      public void updateChart()
      Updates the chart on the client-side.
    • reset

      public void reset()
      Resets the chart to its initial state.
    • render

      public void render()
      Renders the chart.
    • stop

      public void stop()
      Stops any running animations.
    • resize

      public void resize()
      Resizes the chart.
    • destroy

      public void destroy()
      Destroys the chart instance.
    • initialize

      protected void initialize()
      Overrides:
      initialize in class ChartJsComponent<CjChart>