Package com.oorian.chartjs
Class CjChart
java.lang.Object
com.oorian.html.Element<CjChart>
- Direct Known Subclasses:
CjBarChart,CjBubbleChart,CjDoughnutChart,CjLineChart,CjPieChart,CjPolarAreaChart,CjRadarChart,CjScatterChart
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddDataset(CjDataset dataset) Adds a dataset to the chart.voiddestroy()Destroys the chart instance.Gets the datasets.Gets the chart labels.Gets the plugins configuration.Gets the scales configuration.protected voidvoidrender()Renders the chart.voidreset()Resets the chart to its initial state.voidresize()Resizes the chart.setAnimationDuration(int milliseconds) Sets the animation duration.setAnimationsEnabled(boolean enabled) Sets whether animations are enabled.setAspectRatio(double ratio) Sets the aspect ratio.setChartType(ChartType type) Sets the chart type.setChartType(String type) Sets the chart type by string value.Convenience method to quickly add data with a label.Convenience method to quickly add data from a list.setDatasets(List<CjDataset> datasetList) Sets all datasets at once.setHoverMode(InteractionMode mode) Sets the hover mode.setIndexAxis(IndexAxis axis) Sets the index axis for horizontal bar charts.setInteractionIntersect(boolean intersect) Sets whether interaction requires intersecting the element.Sets the interaction mode.Sets the chart labels (x-axis categories).Sets the chart labels from a list.setLegendPosition(LegendPosition position) Sets the legend position.setLegendVisible(boolean visible) Sets whether the legend is visible.setMaintainAspectRatio(boolean maintain) Sets whether to maintain aspect ratio.setOptions(CjChartOptions options) Sets the options configuration directly.setPlugins(CjPlugins plugins) Sets the plugins configuration.setResponsive(boolean responsive) Sets whether the chart is responsive.Sets the scales configuration.setSubtitle(String subtitle) Sets the chart subtitle.Sets the chart title.setTooltipEnabled(boolean enabled) Sets whether tooltips are enabled.setXAxisMax(Number max) Sets the X-axis maximum value.setXAxisMin(Number min) Sets the X-axis minimum value.setXAxisTitle(String title) Sets the X-axis title.setXAxisType(ScaleType type) Sets the X-axis scale type.setYAxisBeginAtZero(boolean beginAtZero) Sets whether the Y-axis begins at zero.setYAxisMax(Number max) Sets the Y-axis maximum value.setYAxisMin(Number min) Sets the Y-axis minimum value.setYAxisTitle(String title) Sets the Y-axis title.setYAxisType(ScaleType type) Sets the Y-axis scale type.voidstop()Stops any running animations.voidUpdates the chart on the client-side.Methods inherited from class com.oorian.chartjs.ChartJsComponent
callMethod, getComponentType, getConfig, setConfig, setHeight, setHeight, setWidth, setWidthMethods inherited from class com.oorian.html.Element
addAttribute, addAttribute, addAttribute, addAttribute, addElement, addLineBreak, addLineOfText, addLineOfText, addLineOfText, addParagraph, addParagraph, addSpacer, addText, addText, addText, addText, assignId, containsElement, containsElement, create, dispatchEvent, dispatchEvent, dispatchEvent, dispatchEvent, equals, excludeId, executeJs, executeJs, executeJs, getAccept, getAllElements, getAncestor, getAttribute, getAttributes, getComponent, getDir, getElement, getElementById, getElementCount, getElementCount, getElements, getElements, getElementsByComponentName, getElementsByTagName, getHtml, getHtml, getId, getInnerHtml, getInnerHtml, getIs, getItemId, getItemProp, getItemRef, getItemType, getLang, getNextSibling, getPage, getParent, getPart, getPrevSibling, getSlot, getTagName, getTextContent, getUrl, hasAttribute, hasElements, hidden, insertElement, isChildOf, isClosedTag, isCreated, isDescendantOf, isDescendantOf, isInitialized, isItemScope, isTranslate, onCallback, onCreated, onElementAdded, onElementRemoved, onHashChange, onHidden, onInitialized, onJsReturn, onPageLoaded, onPageUnloaded, onRefresh, onRemovedFromPage, onShown, onUpdated, onUserEvent, prewrite, recreate, refresh, refresh, registerAddition, registerListener, registerListener, registerListener, registerListener, registerListener, registerListener, registerListener, registerSubtraction, registerUpdate, removeAllElements, removeAttribute, removeAttribute, removeElement, removeElement, removeFromParent, requestCallback, requestCallback, requestCallback, requestCallback, resetId, scrollTo, scrollToBottom, scrollToTop, self, sendCommand, sendUpdate, setAccept, setComponent, setDir, setDir, setElement, setId, setIs, setItemId, setItemProp, setItemRef, setItemScope, setItemType, setLang, setOnError, setOnLoad, setPage, setParent, setPart, setSlot, setTagName, setText, setText, setText, setText, setTranslate, shown, toString, unregisterListener, update, updateAttributes
-
Constructor Details
-
CjChart
public CjChart()Creates a new chart with the default type (line). -
CjChart
Creates a new chart with the specified type.- Parameters:
type- The chart type
-
-
Method Details
-
setChartType
Sets the chart type.- Parameters:
type- The chart type- Returns:
- This instance for method chaining
-
setChartType
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
Sets the chart labels (x-axis categories).- Parameters:
labelValues- The label values- Returns:
- This instance for method chaining
-
setLabels
Sets the chart labels from a list.- Parameters:
labelValues- The label values- Returns:
- This instance for method chaining
-
getLabels
Gets the chart labels.- Returns:
- The labels list
-
addDataset
Adds a dataset to the chart.- Parameters:
dataset- The dataset to add- Returns:
- This instance for method chaining
-
setDatasets
Sets all datasets at once.- Parameters:
datasetList- The list of datasets- Returns:
- This instance for method chaining
-
getDatasets
Gets the datasets.- Returns:
- The datasets list
-
setData
Convenience method to quickly add data with a label.- Parameters:
label- The dataset labelvalues- The data values- Returns:
- This instance for method chaining
-
setData
Convenience method to quickly add data from a list.- Parameters:
label- The dataset labelvalues- The data values- Returns:
- This instance for method chaining
-
setOptions
Sets the options configuration directly.- Parameters:
options- The options configuration- Returns:
- This instance for method chaining
-
setScales
Sets the scales configuration.- Parameters:
scales- The scales configuration- Returns:
- This instance for method chaining
-
getScales
Gets the scales configuration.- Returns:
- The scales config, or null if not set
-
setXAxisType
Sets the X-axis scale type.- Parameters:
type- The scale type- Returns:
- This instance for method chaining
-
setYAxisType
Sets the Y-axis scale type.- Parameters:
type- The scale type- Returns:
- This instance for method chaining
-
setXAxisMin
Sets the X-axis minimum value.- Parameters:
min- The minimum value- Returns:
- This instance for method chaining
-
setXAxisMax
Sets the X-axis maximum value.- Parameters:
max- The maximum value- Returns:
- This instance for method chaining
-
setYAxisMin
Sets the Y-axis minimum value.- Parameters:
min- The minimum value- Returns:
- This instance for method chaining
-
setYAxisMax
Sets the Y-axis maximum value.- Parameters:
max- The maximum value- Returns:
- This instance for method chaining
-
setXAxisTitle
Sets the X-axis title.- Parameters:
title- The axis title- Returns:
- This instance for method chaining
-
setYAxisTitle
Sets the Y-axis title.- Parameters:
title- The axis title- Returns:
- This instance for method chaining
-
setYAxisBeginAtZero
Sets whether the Y-axis begins at zero.- Parameters:
beginAtZero- True to begin at zero- Returns:
- This instance for method chaining
-
setIndexAxis
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
Sets the plugins configuration.- Parameters:
plugins- The plugins configuration- Returns:
- This instance for method chaining
-
getPlugins
Gets the plugins configuration.- Returns:
- The plugins config, or null if not set
-
setTitle
Sets the chart title.- Parameters:
title- The chart title- Returns:
- This instance for method chaining
-
setSubtitle
Sets the chart subtitle.- Parameters:
subtitle- The chart subtitle- Returns:
- This instance for method chaining
-
setLegendPosition
Sets the legend position.- Parameters:
position- The legend position- Returns:
- This instance for method chaining
-
setLegendVisible
Sets whether the legend is visible.- Parameters:
visible- True to show the legend- Returns:
- This instance for method chaining
-
setTooltipEnabled
Sets whether tooltips are enabled.- Parameters:
enabled- True to enable tooltips- Returns:
- This instance for method chaining
-
setResponsive
Sets whether the chart is responsive.- Parameters:
responsive- True for responsive sizing- Returns:
- This instance for method chaining
-
setMaintainAspectRatio
Sets whether to maintain aspect ratio.- Parameters:
maintain- True to maintain aspect ratio- Returns:
- This instance for method chaining
-
setAspectRatio
Sets the aspect ratio.- Parameters:
ratio- The aspect ratio (width/height)- Returns:
- This instance for method chaining
-
setInteractionMode
Sets the interaction mode.- Parameters:
mode- The interaction mode- Returns:
- This instance for method chaining
-
setInteractionIntersect
Sets whether interaction requires intersecting the element.- Parameters:
intersect- True to require intersection- Returns:
- This instance for method chaining
-
setHoverMode
Sets the hover mode.- Parameters:
mode- The hover mode- Returns:
- This instance for method chaining
-
setAnimationDuration
Sets the animation duration.- Parameters:
milliseconds- Duration in milliseconds- Returns:
- This instance for method chaining
-
setAnimationsEnabled
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:
initializein classChartJsComponent<CjChart>
-