Swift Charts line, bar, pie, and other marks under One.iOS.Chart
One.iOS.Chart draws a Swift Charts chart. Each data point becomes one mark
of the chosen type: line, point, bar, area, pie, or rectangle.
referenceLines draw horizontal rule marks at their y values, and each
mark type takes its own style object.
Reach for it for in-app analytics and summaries: weekly bars, a line with a goal rule, or a pie of categories. A chart fills the box React Native gives it, so give it a height. It throws on web and Android.
import { One } from 'one'
function Week() { return ( <One.iOS.Chart type="bar" data={[ { x: 'Mon', y: 3 }, { x: 'Tue', y: 7 }, { x: 'Wed', y: 5 }, ]} referenceLines={[{ x: 'goal', y: 6 }]} barStyle={{ cornerRadius: 4 }} showLegend style={{ height: 220 }} /> )}The bars plot on a category axis with a red goal rule at 6. The legend names
each x category.
Points validate in JavaScript before they reach native: x must be a string
or finite number, y a finite number, and each style object must carry only
its own type’s keys. A string x plots on a category axis, a number on a
numeric axis. Colors take a color string or a processed color number.
When no point sets color, bars and pie sectors take a category color for
each x and the legend names them. When any point sets color, every mark
uses its own point’s color and the rest are blue. Line, point, area, and
rectangle marks are blue unless their style or point names a color, and
reference lines are red unless their point or ruleStyle names one.
| Props | Type | Description |
|---|---|---|
data (required)readonly ChartDataPoint[]Points, each { x, y, color }. A string x plots on a category axis, a number on a numeric axis. | readonly ChartDataPoint[] | Points, each { x, y, color }. A string x plots on a category axis, a number on a numeric axis. |
typeChartType = "line"line, point, bar, area, pie, or rectangle. | ChartType = "line" | line, point, bar, area, pie, or rectangle. |
showGridboolean = trueShows both axes and their grid lines. | boolean = true | Shows both axes and their grid lines. |
animateboolean = trueAnimates the marks when the number of points changes. | boolean = true | Animates the marks when the number of points changes. |
showLegendboolean = falseShows the legend for category colors. | boolean = false | Shows the legend for category colors. |
referenceLinesreadonly ChartDataPoint[] = []Horizontal rules at each y, red unless a color is set. | readonly ChartDataPoint[] = [] | Horizontal rules at each y, red unless a color is set. |
lineStyleLineChartStyleLine marks. | LineChartStyle | Line marks. |
pointStylePointChartStylePoint marks. | PointChartStyle | Point marks. |
areaStyleAreaChartStyleArea marks. | AreaChartStyle | Area marks. |
barStyleBarChartStyleBar marks. | BarChartStyle | Bar marks. |
pieStylePieChartStylePie sectors. | PieChartStyle | Pie sectors. |
rectangleStyleRectangleChartStyleRectangle marks. | RectangleChartStyle | Rectangle marks. |
ruleStyleRuleChartStyleReference lines. | RuleChartStyle | Reference lines. |
A style object takes only the keys of its own type; any other key throws.
| LineChartStyle | Type | Description |
|---|---|---|
dashArrayreadonly number[]Dash and gap lengths in points. | readonly number[] | Dash and gap lengths in points. |
widthnumber = 2Line width in points. | number = 2 | Line width in points. |
pointStyleChartPointStyle = "circle"circle, square, or diamond. | ChartPointStyle = "circle" | circle, square, or diamond. |
pointSizenumber = 6Symbol size. | number = 6 | Symbol size. |
colorColorValueThe line color. | ColorValue | The line color. |
| PointChartStyle | Type | Description |
|---|---|---|
pointStyleChartPointStyle = "circle"circle, square, or diamond. | ChartPointStyle = "circle" | circle, square, or diamond. |
pointSizenumber = 6Symbol size. | number = 6 | Symbol size. |
| AreaChartStyle | Type | Description |
|---|---|---|
colorColorValueThe fill color. | ColorValue | The fill color. |
| BarChartStyle | Type | Description |
|---|---|---|
cornerRadiusnumber = 0Corner radius in points. | number = 0 | Corner radius in points. |
widthnumberA fixed bar width in points. Swift Charts sizes bars when unset. | number | A fixed bar width in points. Swift Charts sizes bars when unset. |
| PieChartStyle | Type | Description |
|---|---|---|
innerRadiusnumber = 0.3The hole as a fraction of the radius; 0 draws a full pie. | number = 0.3 | The hole as a fraction of the radius; 0 draws a full pie. |
angularInsetnumber = 2The gap between sectors in points. | number = 2 | The gap between sectors in points. |
| RectangleChartStyle | Type | Description |
|---|---|---|
colorColorValueThe fill when a point sets none. | ColorValue | The fill when a point sets none. |
cornerRadiusnumber = 0Corner radius in points. | number = 0 | Corner radius in points. |
| RuleChartStyle | Type | Description |
|---|---|---|
colorColorValueThe line color when a reference line sets none. | ColorValue | The line color when a reference line sets none. |
lineWidthnumber = 2Line width in points. | number = 2 | Line width in points. |
dashArrayreadonly number[]Dash and gap lengths in points. | readonly number[] | Dash and gap lengths in points. |
The chart types are exported from one:
import type { ChartDataPoint } from 'one'.
| iOS | Android | Web | |
|---|---|---|---|
| Renders | Swift Charts | Throws | Throws |
| Marks | Native marks | None | None |
x or y, an unknown style key,
or a non-color throws during render.Edit this page on GitHub.