Charts
Bar, line, area, pie and donut charts whose data changes from fields and buttons.
Chart
chartType picks the kind: bar, line, area, pie, donut or scatter. labels are the categories (x axis) and series the data: { key, name, data: [numbers] }. A series can be type: "line" inside a bar chart.
Options add the rest: stacked, horizontal, format (currency, ...), rulers (reference lines), dataLabels, pointRules (colors by value), hover effect, highlight, tableToggle and animation.
Fields and buttons change a chart through actions: api.setChartType, setChartValue, setChartData, addChartPoint, highlightChart, toggleSeries, or any prop with setNodeProps.
Try it
Code
Copy Full page.js into app/your-page/page.js of a Next.js app (withrcube-html, react-bootstrap and Bootstrap's CSS installed) — it runs as is. Or copy only the schema and keep your own page.
[
{
"type": "row",
"id": "row-controls",
"children": [
{
"type": "column",
"id": "c-type",
"props": {
"className": "col-12 col-md-4"
},
"children": [
{
"type": "SelectField",
"id": "type",
"props": {
"name": "chartType",
"label": "Chart type",
"defaultValue": "bar",
"onChange": "typeChanged()",
"options": [
{
"label": "Bar",
"value": "bar"
},
{
"label": "Line",
"value": "line"
},
{
"label": "Area",
"value": "area"
},
{
"label": "Pie",
"value": "pie"
},
{
"label": "Donut",
"value": "donut"
}
]
}
}
]
},
{
"type": "column",
"id": "c-slider",
"props": {
"className": "col-12 col-md-4"
},
"children": [
{
"type": "SliderField",
"id": "march",
"props": {
"name": "march",
"label": "March online sales",
"min": 0,
"max": 100,
"defaultValue": 38,
"valueSuffix": "K",
"onChange": "marchChanged()"
}
}
]
},
{
"type": "column",
"id": "c-switches",
"props": {
"className": "col-12 col-md-4 d-flex gap-3 align-items-center"
},
"children": [
{
"type": "InputField",
"id": "stacked",
"props": {
"type": "checkbox",
"name": "stacked",
"label": "Stacked",
"onChange": "stackedChanged()"
}
},
{
"type": "InputField",
"id": "labels",
"props": {
"type": "checkbox",
"name": "labels",
"label": "Values",
"onChange": "labelsChanged()"
}
}
]
}
]
},
{
"type": "row",
"id": "row-buttons",
"children": [
{
"type": "column",
"id": "c-buttons",
"props": {
"className": "d-flex flex-wrap gap-2 mb-3"
},
"children": [
{
"type": "ButtonField",
"id": "random",
"props": {
"text": "Randomize",
"onClick": "randomize()"
}
},
{
"type": "ButtonField",
"id": "add",
"props": {
"text": "+ Add month",
"onClick": "addMonth()"
}
},
{
"type": "ButtonField",
"id": "best",
"props": {
"text": "Highlight best month",
"variant": "outline-success",
"onClick": "highlightBest()"
}
},
{
"type": "ButtonField",
"id": "store",
"props": {
"text": "Show / hide Store",
"variant": "outline-secondary",
"onClick": "toggleStore()"
}
}
]
}
]
},
{
"type": "Chart",
"id": "sales",
"props": {
"chartType": "bar",
"title": "Monthly sales",
"subtitle": "Thousands of USD",
"height": 300,
"labels": [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun"
],
"series": [
{
"key": "online",
"name": "Online",
"data": [
42,
51,
38,
64,
58,
71
]
},
{
"key": "store",
"name": "Store",
"data": [
30,
28,
35,
31,
40,
37
]
},
{
"key": "target",
"name": "Target",
"type": "line",
"dashed": true,
"data": [
45,
48,
50,
55,
60,
65
]
}
],
"format": "number",
"yAxis": {
"title": "Sales (K)"
},
"rulers": [
{
"value": 60,
"label": "Goal",
"showValue": true
}
],
"pointRules": [
{
"when": {
"lt": 32
},
"color": "#d03b3b"
}
],
"highlightColor": "#0ca30c",
"tableToggle": true,
"onPointClick": "pointClicked()",
"onLegendClick": "legendClicked()"
}
}
]Options used here
| Option | What it does |
|---|---|
chartType | bar, line, area, pie, donut, scatter. |
labels / series | Categories and { key, name, data, type, color, dashed } series. |
stacked / horizontal | Stack the bars / areas; draw bars sideways. |
format / currency / decimals | How values are written (tooltip, labels, table). |
yAxis / xAxis | { title, min, max, ticks, show }. |
rulers / bands | Reference lines { value, label } / shaded ranges { from, to }. |
dataLabels | all, last, max, minmax (pie: true = percent). |
pointRules / highlight / highlightColor / hover / hoverColor | Colors by value, highlighted marks, hover effect. |
tableToggle / legend / tooltip / animate | Table view button, legend position, tooltips, animation. |
Events
| Event | When it runs | Your action receives |
|---|---|---|
onPointClick / onPointHover | A bar / point / slice is clicked or hovered. | { chart, index, label, series, seriesName, value, values } |
onLegendClick | A legend item is clicked. | { chart, series, hidden } |