Class ChartDef
chart card.
Produces the same contract entry as <@card type="chart">; PageSpec runs it through
ChartCardType when the page renders. The factories are line(String), bar(String),
donut(String), heatmap(String), scatter(String), pie(String), treemap(String) and
raw(String). line, bar and donut emit the flat legacy form
(kind:"line", x:..., series:[...]) byte-for-byte; the other kinds emit helper:{kind, ...}, and
raw emits neither (its option(JsonMap) is the whole chart).
Example:
- Since:
- 10.0.0
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionAdds dialog actions that other actions can open as steps.static ChartDefstatic ChartDefstatic ChartDefheight(int px) Draws bars horizontally.largeData(int threshold) largeData(int threshold, boolean progressive) static JsonMaplegendItem(String value, String label, String tone) One entry of a treemap colour key.static ChartDefonClickAction(RowAction action) Runs a row action when a mark is clicked.onClickHref(String template) onTopicAction(String topic, RowAction action) Runs a row action when a topic this card publishes fires.Draws partial frames during a chunkedsourceload.static ChartDefPublishes the legend selection onlegend:<id>.Publishes the zoom window onzoom:<id>.static ChartDefA chart with no helper.refreshMs(long ms) static ChartDefSets a body key that has no dedicated method (for example an ECharts-level card key the glue reads).stacked(boolean v) symbolSizeBy(String field) tileFields(String... fields) static ChartDefA treemap: rows nested into boxes bygroupBy(String...), one tile per row, with pan and zoom.visibleWhen(VisibilityRule... rules)
-
Field Details
-
MIN_HEIGHT
Minimum chart height in pixels.- See Also:
-
-
Method Details
-
line
- Parameters:
id- The card id. @return A new line chart.
-
bar
- Parameters:
id- The card id. @return A new bar chart.
-
donut
- Parameters:
id- The card id. @return A new donut chart.
-
heatmap
- Parameters:
id- The card id. @return A new heatmap (category x, category y, a value field).
-
scatter
- Parameters:
id- The card id. @return A new scatter chart.
-
pie
- Parameters:
id- The card id. @return A new pie chart.
-
treemap
A treemap: rows nested into boxes bygroupBy(String...), one tile per row, with pan and zoom.A click on a tile publishes the row's
tileFields(String...)asmeta(the tile'srowis alwaysnull ); a click on a group does nothing.Example:
ChartDef.
treemap ("fleet" ).src("/api/hosts" ).groupBy("region" ,"cluster" ).label("host" ) .colorBy("health" , ChartDef.legendItem ("ok" ,"Healthy" ,"ok" ), ChartDef.legendItem ("down" ,"Down" ,"danger" )) .tileFields("host" ,"health" );- Parameters:
id- The card id.- Returns:
- A new treemap; set its groups with
groupBy(String...)and its tile label withlabel(String).
-
raw
A chart with no helper. Anything ECharts draws works this way, for example a box plot:ChartDef.
raw ("latency" ).src("/stats/latency" ) .option("{xAxis:{type:'category'},yAxis:{},series:[{type:'boxplot',encode:{x:'day',y:['lo','q1','med','q3','hi']}}]}" );- Parameters:
id- The card id.- Returns:
- A new chart with no helper; set its ECharts option with
option(JsonMap).
-
title
- Parameters:
v- The card title. @return This object.
-
src
- Parameters:
v- A same-origin URL returning an array of rows or{rows:[...]}. @return This object.
-
data
- Parameters:
rows- Inline rows (flat maps). @return This object.
-
x
- Parameters:
field- The x (category) field. @return This object.
-
x
- Parameters:
field- The x field.type-category(default),numberortime;null for the default.label- The axis label, ornull .- Returns:
- This object.
-
y
- Parameters:
label- The value-axis label, ornull .min- The axis minimum, ornull for 0 (or the data minimum when negative).format-integer,decimal,percentorcompact;null for the default.- Returns:
- This object.
-
series
- Parameters:
field- A numeric row field. @param label The legend label. @return This object.
-
series
- Parameters:
field- A numeric row field. @param label The legend label. @param tone Palette slot 1-8. @return This object.
-
series
- Parameters:
field- A numeric row field. @param label The legend label. @param tonedanger,okorwarning. @return This object.
-
stacked
- Parameters:
v- Whether bar series stack. @return This object.
-
horizontal
Draws bars horizontally. @return This object. -
legend
- Parameters:
v-bottom(default),rightornone. @return This object.
-
height
- Parameters:
px- The plot height, at leastMIN_HEIGHT. @return This object.
-
refreshMs
- Parameters:
ms- The re-fetch interval, at leastSafePathTemplate.MIN_POLL_INTERVAL_MS. @return This object.
-
onClickHref
- Parameters:
template- A same-origin path template (SafePathTemplate.isSameOriginPath(String));{field}is replaced with the clicked row's value.- Returns:
- This object.
-
onClickAction
Runs a row action when a mark is clicked.A treemap tile runs it; clicking a treemap group header only zooms and runs nothing.
Declares
on("click", "<id>.click")unless a click topic is already declared, and runsactionwhenever that topic fires. Exclusive withonClickHref(String). The action is refused unless it has anendpoint(and, if set, aform) that is a same-origin path, a non-safemethod, and nopresentother thandialog, and does not navigate on success.- Parameters:
action- The action; its id must be unique across the card's actions.- Returns:
- This object.
- Throws:
IllegalArgumentException- If the action is not valid on a chart,onClickHref(String)was set, or no click topic can be derived: the id must match[a-z][a-z0-9-]{0,31} , or callon(String, String)with"click" first.
-
onTopicAction
Runs a row action when a topic this card publishes fires.Only a click has a keyboard equivalent (Enter on the focused point synthesizes a click); an action bound to another event, such as
dblclick, is reachable by pointer only. A treemap group node publishes no events.- Parameters:
topic- A topic declared throughon(String, String).action- The action; its id must be unique across the card's actions.- Returns:
- This object.
- Throws:
IllegalArgumentException- If the topic is not declared, or the action is not valid on a chart.
-
actions
Adds dialog actions that other actions can open as steps.Each entry must have
presentset todialog, and obeys the same rules asonClickAction(RowAction). Calls accumulate.- Parameters:
actions- The actions; ids must be unique across the card's actions.- Returns:
- This object.
- Throws:
IllegalArgumentException- If an entry isnull , is not a dialog action, or is not valid on a chart.
-
emptyText
- Parameters:
v- The text shown when there are no rows. @return This object.
-
groupBy
- Parameters:
fields- The treemap group fields, outermost first; at least one, each non-blank. @return This object.
-
size
- Parameters:
field- The numeric treemap field that sizes each tile; without it every tile has the same size. @return This object.
-
colorBy
- Parameters:
field- The treemap field whose value picks each tile's colour.legend- The colour key, onelegendItem(String, String, String)per value; a value with no entry is neutral.- Returns:
- This object.
-
tileFields
- Parameters:
fields- The row fields a tile click publishes asmetaand its tooltip shows; each matches[A-Za-z0-9_.-]+. @return This object.
-
legendItem
One entry of a treemap colour key.- Parameters:
value- The field value this entry matches.label- The key text; defaults to the value.tone-ok,warning,danger,--jc-chart-1to--jc-chart-8, ornull for neutral.- Returns:
- The entry, for
colorBy(String, JsonMap...).
-
label
- Parameters:
field- The donut slice-label field, or the treemap tile-label field. @return This object.
-
value
- Parameters:
field- The donut slice-value field. @return This object.
-
center
- Parameters:
v-totalor literal center text. @return This object.
-
option
- Parameters:
v- A raw ECharts option (JSON only; functions throughFn). @return This object.
-
option
- Parameters:
json5- A raw ECharts option as JSON5, parsed bytoCardSpec(). @return This object.
-
decorate
- Parameters:
d- A decorator; atopicit names is added to the card'spublishes. @return This object.
-
decorate
- Parameters:
name- A dotted app decorator name (or a built-in). @param args Its arguments (nousekey). @return This object.
-
patch
- Parameters:
v- Deep-merged into the final option (objects by key, arrays by elementid). @return This object.
-
patch
- Parameters:
json5- A patch as JSON5, parsed bytoCardSpec(). @return This object.
-
on
- Parameters:
event- An ECharts event name matching^[a-z][a-z0-9_]{0,31}$.topic- A custom topic; added to the card'spublishes.- Returns:
- This object.
-
publishZoom
Publishes the zoom window onzoom:<id>. @return This object. -
publishLegend
Publishes the legend selection onlegend:<id>. @return This object. -
group
- Parameters:
v- A connect group shared with other chart cards. @return This object.
-
renderer
- Parameters:
v-canvas(default) orsvg. @return This object.
-
theme
- Parameters:
v- An ECharts theme name registered in the page; the default is the page theme. @return This object.
-
source
- Parameters:
dataTopic- Adata:topic (Topics.data(String)). @return This object.
-
yField
- Parameters:
field- The heatmap y (category) field. @return This object.
-
scale
- Parameters:
min- The heatmap colour-scale minimum. @param max Its maximum. @return This object.
-
symbolSizeBy
- Parameters:
field- The scatter field sized by square root. @return This object.
-
largeData
- Parameters:
threshold- Rows above which the large-data defaults apply. @return This object.
-
largeData
- Parameters:
threshold- Rows above which the large-data defaults apply. @param progressivetruesets progressive to the threshold;falseleaves the JS default (5000). @return This object.
-
partialFrames
Draws partial frames during a chunkedsourceload. @return This object. -
a11y
- Parameters:
summary- The figure caption, ornull for the generated one. @param table Show the data-table toggle. @return This object.
-
map
- Parameters:
name- An ECharts map name. @param path A same-origin path to its GeoJSON. @return This object.
-
set
Sets a body key that has no dedicated method (for example an ECharts-level card key the glue reads). For a helper kind, a helper key set here is routed underhelper.- Parameters:
key- A key with no dedicated method.value- Its value.- Returns:
- This object.
-
visibleWhen
- Parameters:
rules- Card-level visibility rules, ANDed. @return This object.
-
toCardSpec
- Returns:
- The
chartcard. - Throws:
IllegalArgumentException- If not exactly one ofsrc/data/sourceis set, a kind's required keys are missing,rawhas no option, or an option/patch string is not valid JSON5.
-