Overview
TheSlice class draws a slice shape, commonly used in pie and donut charts. It extends the Graphics base class and provides properties for controlling radius, arc, angles, and more.
Class Definition
Settings Interface
Properties
Radius in pixels.This defines the outer radius of the slice.
Slice “width” in degrees.The angular width of the slice. For example, 90 degrees creates a quarter circle.
Inner radius of the slice in pixels.Set this to create a donut-style slice. A value of 0 creates a pie slice.
Start angle in degrees.The angle at which the slice begins. 0 degrees is at the top (12 o’clock position).
Slice corner radius in pixels.Rounds the corners of the slice edges.
Slice “pull out” radius in pixels.Use this to pull a slice out from the center (exploded slice effect).
Number of pixels to add to whatever slice’s
radius value is.Negative numbers can also be used. This is useful for relative adjustments.Number of pixels to add to whatever slice’s
innerRadius value is.Negative numbers can also be used. This is useful for relative adjustments.Public Properties
The x component of the slice’s middle angle direction vector.This is calculated automatically and used for positioning tooltips and applying shift radius.
The y component of the slice’s middle angle direction vector.This is calculated automatically and used for positioning tooltips and applying shift radius.
Inherited Properties
AsSlice extends Graphics, it inherits all graphics properties including:
Stroke (border) color.Learn more about colors, gradients and patterns
Width of the stroke (border) in pixels.
Opacity of the fill. 0 - fully transparent; 1 - fully opaque.
Opacity of the stroke (border). 0 - fully transparent; 1 - fully opaque.
Fill pattern.Learn more about patterns
Stroke (border) pattern.Learn more about patterns
Fill gradient.Learn more about gradients
Stroke (border) gradient.Learn more about gradients
Stroke (border) dash settings.Learn more about dashed lines
Stroke (border) dash offset.Learn more about dashed lines
Color of the element’s shadow.For this to work at least one of the following needs to be set as well:
shadowBlur, shadowOffsetX, shadowOffsetY.Learn more about shadowsBlurriness of the shadow. The bigger the number, the more blurry shadow will be.Learn more about shadows
Horizontal shadow offset in pixels.Learn more about shadows
Vertical shadow offset in pixels.Learn more about shadows
Opacity of the shadow (0-1).If not set, will use the same as
fillOpacity of the element.Learn more about shadowsExample Usage
Pie Slice
Donut Slice
Exploded Slice
Dynamic Radius Adjustment
Notes
- The slice uses the d3-shape arc generator internally for rendering.
- If
innerRadiusis negative, it’s treated as relative to the outer radius. - The
shiftRadiusproperty automatically updates thedxanddyproperties to shift the slice outward from the center. - Full circle (360 degrees) with
innerRadiusof 0 is treated specially for tooltip positioning. - The corner radius is only applied when the arc is greater than 0.1 degrees to avoid rendering issues.
See Also
- Graphics documentation
- Circle - For full circle shapes
- Pie Charts - For using slices in pie charts