LightChart is a lightweight SwiftUI package with line charts implementation. You can use it when you need only a chart that will perfectly fit into your View. It doesn’t have any interaction, titles, different types of diagram or anything else, just a representation of your data set.
Currently LightChart have only line type of chart with sharp corners or a curved one. That’s how it looks in the real application on currency exchange rates example:
Installation
It’s a Swift Package, so you need to do the following:
Open File in Xcode menu
Open Swift Packages
Choose Add Package Dependency... option
In the Enter package repository URL field paste this URL: https://github.com/pichukov/LightChart
Choose any existing version or a master branch option
Usage
Add import LightChart
Add LightChartView into your SwiftUI code
LightChartView(data: [4, 8, 12, 10, 25])
By default it will draw a red line chart:
To customize it you can use several properties:
type
The type of chart, it’s an enum with two cases:
.line is a default type that will draw a chart presented above
By default the offset is 0 and it means that the chart takes up the entire area of the parent view. You can move the chart line up with changing the offset value. For example if you will use the offset: 0.2 you chart line will move up and take only 80% of the parent view
LightChart is a lightweight SwiftUI package with line charts implementation. You can use it when you need only a chart that will perfectly fit into your View. It doesn’t have any interaction, titles, different types of diagram or anything else, just a representation of your data set.
Currently
LightCharthave onlylinetype of chart with sharp corners or a curved one. That’s how it looks in the real application on currency exchange rates example:Installation
It’s a Swift Package, so you need to do the following:
Filein Xcode menuSwift PackagesAdd Package Dependency...optionEnter package repository URLfield paste this URL:https://github.com/pichukov/LightChartmasterbranch optionUsage
Add
import LightChartAddLightChartViewinto your SwiftUI codeBy default it will draw a red line chart:
To customize it you can use several properties:
type
The type of chart, it’s an
enumwith two cases:.lineis a default type that will draw a chart presented above.curvedwill draw a curved chart, for example:visualType
The visual part of the chart. An
enumwith three cases:.outline(color: Color, lineWidth: CGFloat)to specify acolorandlineWidthforstroke.filled(color: Color, lineWidth: CGFloat)use stroke color to fill the chart with a gradient.customFilled(color: Color, lineWidth: CGFloat, fillGradient: LinearGradient)also provides an option to change the fill gradientoffset
By default the
offsetis0and it means that the chart takes up the entire area of the parent view. You can move the chart line up with changing theoffsetvalue. For example if you will use theoffset: 0.2you chart line will move up and take only 80% of the parent viewcurrentValueLineType
There is an option to add a horizontal line that will point the last value of the data set. A
currentValueLineTypeis anenumthat has three cases:.noneis a default value that doesn’t show any line.line(color: Color, lineWidth: CGFloat)adds a line withcolorandlineWidthfor astroke.dash(color: Color, lineWidth: CGFloat, dash: [CGFloat])adds a dashed line