SwiftUICharts
A charts / plotting library for SwiftUI. Works on macOS, iOS, watchOS, and tvOS.
Examples
Line Chart
View
Data Model
View
Data Model
Bar Chart
View
Data Model
View
Data Model
Documentation
All data and most styling is passed into the view by an Environment Object. See ChartData.
View Modifiers
Touch Overlay
Detects input either from touch of pointer. Finds the nearest data point and displays the relevent information.
The location of the info box is set in ChartStyle.
- specifier: Decimal precision for labels
Setup within ChartData --> ChartStyle
Point Markers
Lays out markers over each of the data point.
Setup within ChartData --> PointStyle
Average Line
Shows a marker line at the average of all the data points.
- markerName: Title of marker, for the legend
- lineColour: Line Colour
- strokeStyle: Style of Stroke
Y Axis Point Of Interest
Configurable Point of interest
- markerName: Title of marker, for the legend
- markerValue : Chosen point.
- lineColour: Line Colour
- strokeStyle: Style of Stroke
X Axis Grid
Adds vertical lines along the X axis.
Setup within ChartData --> ChartStyle --> GridStyle.
Y Axis Grid
Adds horizontal lines along the Y axis.
Setup within ChartData --> ChartStyle --> GridStyle.
X Axis Labels
Labels for the X axis.
Setup within ChartData --> ChartStyle --> XAxisLabelSetup
Y Axis Labels
Automatically generated labels for the Y axis
- specifier: Decimal precision specifier.
Setup within ChartData --> ChartStyle --> YAxisLabelSetup
Header Box
Displays the metadata about the chart. See ChartMetadata
Legends
Legends from the data being show on the chart (See ChartMetadata ) and any markers (See Average Line and Y Axis Point Of Interest).
Lays out markers over each of the data point.
Data Models
ChartData
The ChartData type is where the majority of the configuration is done. The only required initialiser is dataPoints.
- dataPoints: Array of ChartDataPoints. See ChartDataPoint.
- metadata: Data to fill in the metadata box above the chart. See ChartMetadata.
- xAxisLabels: Array of Strings for when there are too many data points to show all xAxisLabels.
- chartStyle : The parameters for the aesthetic of the chart. See ChartStyle.
- lineStyle: The parameters for the aesthetic of the line chart. See LineChartStyle.
- barStyle: The parameters for the aesthetic of the bar chart. See BarStyle.
- pointStyle: The parameters for the aesthetic of the data point markers. See PointStyle.
- calculations: Choose whether to perform calculations on the data points. If so, then by what means.
ChartDataPoint
ChartDataPoint holds the information for each of the individual data points.
Colours are only used in Bar Charts.
All
- value: Value of the data point.
- xAxisLabel: Label that can be shown on the X axis.
- pointLabel: A longer label that can be shown on touch input.
- date: Date of the data point if any data based calculations are required.
Single Colour
- colour: Colour for use with a bar chart.
Colour Gradient
- colours: Colours for Gradient
- startPoint: Start point for Gradient
- endPoint: End point for Gradient
Colour Gradient with stop control
- stops: Colours and Stops for Gradient with stop control.
- startPoint: Start point for Gradient.
- endPoint: End point for Gradient.
ChartMetadata
Data model for the chart's metadata
- title: The charts Title
- subtitle: The charts subtitle
- lineLegend: The title for the legend
ChartStyle
Model for controlling the overall aesthetic of the chart.
- infoBoxPlacement: Placement of the information box that appears on touch input.
- xAxisGridStyle: Style of the vertical lines breaking up the chart. See GridStyle.
- yAxisGridStyle: Style of the horizontal lines breaking up the chart. See GridStyle.
- xAxisLabelPosition: Location of the X axis labels - Top or Bottom
- xAxisLabelsFrom: Where the label data come from. DataPoint or xAxisLabels
- yAxisLabelPosition: Location of the X axis labels - Leading or Trailing
- yAxisNumberOfLabel: Number Of Labels on Y Axis
- globalAnimation: Gobal control of animations.
GridStyle
Model for controlling the look of the Grid
- numberOfLines: Number of lines to break up the axis
- lineColour: Line Colour
- lineWidth: Line Width
- dash: Dash
- dashPhase: Dash Phase
XAxisLabelSetup
Model for the styling of the labels on the X axis.
- labelPosition: Location of the X axis labels - Top or Bottom
- labelsFrom: Where the label data come from. DataPoint or xAxisLabels
YAxisLabelSetup
Model for the styling of the labels on the Y axis.
- labelPosition: Location of the Y axis labels - Leading or Trailing
- numberOfLabels: Number Of Labels on Y Axis
LineStyle
Model for controlling the overall aesthetic of the line chart.
There are three possible initialisers: Single Colour, Colour Gradient or Colour Gradient with stop control.
Single Colour
- colour: Single Colour
Colour Gradient
- colours: Colours for Gradient
- startPoint: Start point for Gradient
- endPoint: End point for Gradient
Colour Gradient with stop control
- stops: Colours and Stops for Gradient with stop control.
- startPoint: Start point for Gradient.
- endPoint: End point for Gradient.
All
- lineType: Drawing style of the line.
- strokeStyle: Stroke Style
- ignoreZero: Whether the chart should skip data points who's value is 0 while keeping the spacing.
BarStyle
Model for controlling the aesthetic of the bar chart.
There are three possible initialisers: Single Colour, Colour Gradient or Colour Gradient with stop control.
All
- barWidth: How much of the available width to use. 0...1
- cornerRadius: Corner radius of the bar shape.
- colourFrom: Where to get the colour data from.
Single Colour
- colour: Single Colour
Colour Gradient
- colours: Colours for Gradient
- startPoint: Start point for Gradient
- endPoint: End point for Gradient
Colour Gradient with stop control
- stops: Colours and Stops for Gradient with stop control.
- startPoint: Start point for Gradient.
- endPoint: End point for Gradient.
PointStyle
Model for controlling the aesthetic of the point markers.
- pointSize: Overall size of the mark
- borderColour: Outter ring colour
- fillColour: Center fill colour
- lineWidth: Outter ring line width
- pointType: Style of the point marks.
- pointShape: Shape of the points