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
LightChart
have onlyline
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:
File
in Xcode menuSwift Packages
Add Package Dependency...
optionEnter package repository URL
field paste this URL:https://github.com/pichukov/LightChart
master
branch optionUsage
Add
import LightChart
AddLightChartView
into 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
enum
with two cases:.line
is a default type that will draw a chart presented above.curved
will draw a curved chart, for example:visualType
The visual part of the chart. An
enum
with three cases:.outline(color: Color, lineWidth: CGFloat)
to specify acolor
andlineWidth
forstroke
.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
offset
is0
and it means that the chart takes up the entire area of the parent view. You can move the chart line up with changing theoffset
value. For example if you will use theoffset: 0.2
you 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
currentValueLineType
is anenum
that has three cases:.none
is a default value that doesn’t show any line.line(color: Color, lineWidth: CGFloat)
adds a line withcolor
andlineWidth
for astroke
.dash(color: Color, lineWidth: CGFloat, dash: [CGFloat])
adds a dashed line