Class DonutChart
setInnerRadius(float) at 0.
The chart draws its first visible series as the ring: one slice per value, named by the chart's labels and colored by palette slot, because in a donut it is the slices that are the categories. A second series is left undrawn rather than drawn as a second ring; two rings on one chart is a chart nobody can read.
The hole is a real widget slot. setCenter(Widget) puts a widget in the
middle (a total, an icon, a button), laid out in the largest square that fits inside the
ring, and it takes input like any other widget: a button in the hole is clickable, and the
chart's own hover stops at the ring.
Negative values are ignored: they have no share of a whole. Hiding a slice from the legend animates it closed and gives its angle back to the others, because the shares are recomputed from what is still shown.
DonutChart chart = new DonutChart();
chart.setLabels("Direct", "Search", "Social", "Mail");
chart.addSeries(ChartSeries.of("Traffic", 42, 31, 18, 9));
chart.setCenter(new Label("100%").setRole(Label.Role.TITLE));
-
Nested Class Summary
Nested classes/interfaces inherited from class limn.components.chart.Chart
Chart.LegendEntry, Chart.LegendPosition, Chart.TooltipMode -
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncenter()The widget in the hole, ornull.floatThe hole's diameter as a fraction of the ring's.booleanisSliceVisible(int index) Whether sliceindexis currently drawn.protected List<Chart.LegendEntry> One entry per series, in palette order.static DonutChartA donut overlabelsshowingvalues.protected voidonHoverChanged(ChartPoint picked) Called when the datum under the pointer changes,nullwhen there is none: the hook for a chart that animates something on hover.protected voidonLayout()Containers position children here (measure +Widget.layoutBox(float, float, float, float)per child).protected voidpaintContent(Canvas canvas, float x, float y, float w, float h) Paints the marks inside the region left after the title and the legend, in the chart's own coordinates.protected ChartPointpickAt(float localX, float localY) The datum under a point in the chart's local coordinates, ornullwhen the pointer is not over the marks.Puts a widget in the hole.setInnerRadius(float fraction) Sets the hole as a fraction of the outer radius, in[0, 0.95].setSliceColors(Color... colors) Pins the slice colors, in slice order; a shorter array leaves the rest to the palette, andnullhands all of them back to it.setSliceGap(float points) Sets the gap between slices in logical points (0makes them touch).setSliceVisible(int index, boolean visible) Hides or shows one slice; the rest of the ring closes over it, or opens for it.setStartAngle(float degrees) Sets the first slice's starting angle in degrees;-90(the default) is noon.sliceColor(int index) The color of sliceindex: its own, or its palette slot.floatsliceGap()Points of surface between two slices.floatWhere the first slice starts, in degrees clockwise from three o'clock.protected voidtoggleLegendEntry(int index) Hides or shows what legend entryindexstands for.protected ColorThe swatch color for a tooltip row.protected StringtooltipRowName(ChartPoint row) The name a tooltip row carries where reading starts, the series name by default.protected List<ChartPoint> tooltipRows(ChartPoint picked) The rows a tooltip shows forpicked.protected StringThe value a tooltip row carries where reading ends.protected StringtooltipTitle(ChartPoint picked) The series names the ring as a whole ("Traffic"); the row names the slice.Methods inherited from class limn.components.chart.Chart
addSeries, animationBaseline, animationDuration, background, categoryCount, clearSeries, contentBoxHeight, contentBoxWidth, contentLeft, contentTop, dataGeneration, drawnValue, elementProgress, ellipsize, hoveredPoint, isLegendInteractive, isTooltipEnabled, label, labels, labelSource, legendChanged, legendPosition, measure, onAttached, onMeasure, onMouseEvent, onPaint, onPaintOverlay, onPointClick, onPointHover, onSeriesAdded, palette, pointFor, progress, removeSeries, replayAnimation, series, series, seriesAlpha, seriesColor, seriesCount, setAnimationDuration, setAnimationEasing, setBackground, setLabels, setLabels, setLabels, setLegendInteractive, setLegendPosition, setPalette, setPreferredSize, setSeries, setTitle, setTitle, setTooltipEnabled, setTooltipFormat, setTooltipMode, setValueFormat, staggerFraction, stateFadeSeconds, title, titleSource, tokens, tooltipMode, updateRegions, valueFormat, withControlSizeMethods inherited from class limn.scene.Widget
acceptsTextInput, add, baselineOffset, baselineOffsetOf, caretRect, children, clipboard, clipsChildren, controlSize, cursor, declaredControlSize, declaredLayoutDirection, declaredLocale, focusArrivedByTraversal, height, hitTest, imageCursor, invalidate, invalidate, isEnabled, isFocusable, isFocused, isShowing, isVisible, layoutBox, layoutDirection, locale, localToSceneX, localToSceneY, markNeedsContainedLayout, markNeedsLayout, measure, moveChild, neutralBase, onCharTyped, onDetached, onFileDrop, onFocusGained, onFocusLost, onKeyEvent, onPreedit, overlayPassesPointer, paintChildren, paintOutset, paintWidget, parent, remove, requestFocus, revealInView, scene, sceneToLocalX, sceneToLocalY, setControlSize, setCursor, setEnabled, setFocusable, setImageCursor, setInheritanceHost, setLayoutDirection, setLocale, setTooltip, setTooltip, setVisible, shapeText, textRuler, tooltip, width, x, y
-
Constructor Details
-
DonutChart
public DonutChart()
-
-
Method Details
-
of
A donut overlabelsshowingvalues. -
innerRadius
public float innerRadius()The hole's diameter as a fraction of the ring's. -
setInnerRadius
Sets the hole as a fraction of the outer radius, in[0, 0.95].0draws a pie; the default0.62leaves a hole big enough for a headline number. -
startAngle
public float startAngle()Where the first slice starts, in degrees clockwise from three o'clock. -
setStartAngle
Sets the first slice's starting angle in degrees;-90(the default) is noon. -
sliceGap
public float sliceGap()Points of surface between two slices. -
setSliceGap
Sets the gap between slices in logical points (0makes them touch). -
setSliceColors
Pins the slice colors, in slice order; a shorter array leaves the rest to the palette, andnullhands all of them back to it. -
sliceColor
The color of sliceindex: its own, or its palette slot. -
center
The widget in the hole, ornull. -
setCenter
Puts a widget in the hole. It is laid out centred in the largest square that fits inside the ring and is a normal child in every other way: it takes input, it can be a button, and it is measured against that square rather than against the chart.nullempties the hole. -
isSliceVisible
public boolean isSliceVisible(int index) Whether sliceindexis currently drawn. -
setSliceVisible
Hides or shows one slice; the rest of the ring closes over it, or opens for it. -
onLayout
protected void onLayout()Description copied from class:WidgetContainers position children here (measure +Widget.layoutBox(float, float, float, float)per child). -
paintContent
Description copied from class:ChartPaints the marks inside the region left after the title and the legend, in the chart's own coordinates. Grid, axes and everything data-shaped belong here.- Specified by:
paintContentin classChart
-
pickAt
Description copied from class:ChartThe datum under a point in the chart's local coordinates, ornullwhen the pointer is not over the marks. Called for hover and for clicks, so it decides both. -
onHoverChanged
Description copied from class:ChartCalled when the datum under the pointer changes,nullwhen there is none: the hook for a chart that animates something on hover. The application-facing callback isChart.onPointHover(Consumer); this is for subclasses.- Overrides:
onHoverChangedin classChart
-
tooltipRows
Description copied from class:ChartThe rows a tooltip shows forpicked. The default isChart.TooltipMode.INDEX-aware: every visible series at the same index, or just the picked datum inChart.TooltipMode.POINT.- Overrides:
tooltipRowsin classChart
-
tooltipTitle
The series names the ring as a whole ("Traffic"); the row names the slice.- Overrides:
tooltipTitlein classChart
-
tooltipRowName
Description copied from class:ChartThe name a tooltip row carries where reading starts, the series name by default.- Overrides:
tooltipRowNamein classChart
-
tooltipRowValue
Description copied from class:ChartThe value a tooltip row carries where reading ends.- Overrides:
tooltipRowValuein classChart
-
tooltipRowColor
Description copied from class:ChartThe swatch color for a tooltip row.- Overrides:
tooltipRowColorin classChart
-
legendEntries
Description copied from class:ChartOne entry per series, in palette order. Overridden by charts whose legend is not that.- Overrides:
legendEntriesin classChart
-
toggleLegendEntry
protected void toggleLegendEntry(int index) Description copied from class:ChartHides or shows what legend entryindexstands for.- Overrides:
toggleLegendEntryin classChart
-