|
1 | 1 | # SwiftUICharts |
2 | 2 |
|
3 | | -Swift package for displaying charts effortlessly. |
| 3 | +### SwiftUICharts is here with a new version, giving more controll and customization over the charts and full ios 13 backwards compatibility. |
4 | 4 |
|
5 | | - |
| 5 | +SwiftUICharts is an open source library for creating charts in iOS apps with SwiftUI. Built natively with SwiftUI in mind and it is fully compatible with the latest versions of iOS, also backwards **compatible up to iOS 13.** |
6 | 6 |
|
7 | | -It supports: |
8 | | -* Line charts |
9 | | -* Bar charts |
10 | | -* Pie charts |
| 7 | +With SwiftUICharts, you can easily create a variety of chart types, including line charts, bar charts, ring charts and pie charts. It also provides additional chart types and customization options, giving you the flexibility to create charts that perfectly fit your needs. |
11 | 8 |
|
12 | | -### Installation: |
| 9 | +In addition to its native SwiftUI integration, backwards compatibility and wide range of chart types, SwiftUICharts is also easy to use, making it a great choice for creating stunning and intuitive charts in your applications. |
13 | 10 |
|
14 | | -It requires iOS 13 and Xcode 11! |
| 11 | +<p align="center"> |
| 12 | +<img src="Resources/linevid2.gif" width="30%"/> <img src="Resources/barvid2.gif" width="30%"/> <img src="Resources/pievid2.gif" width="30%"/> |
| 13 | +</p> |
15 | 14 |
|
16 | | -In Xcode got to `File -> Swift Packages -> Add Package Dependency` and paste inthe repo's url: `https://github.com/AppPear/ChartView` |
| 15 | +### Composable |
17 | 16 |
|
18 | | -### Usage: |
| 17 | +You can now build your custom chart from prebuilt layers. Use a simple chart, add background grids, add chart labels to the axes, add tcks to the line, etc. |
19 | 18 |
|
20 | | -import the package in the file you would like to use it: `import SwiftUICharts` |
| 19 | +### Works great with native SwiftUI elements |
21 | 20 |
|
22 | | -You can display a Chart by adding a chart view to your parent view: |
| 21 | +[Example codes here]() |
| 22 | +<p align="left"> |
| 23 | +<img src="Resources/linechartcard.png" width="40%"/> <img src="Resources/barchartcard.png" width="40%"/> |
| 24 | +<img src="Resources/piechartcard.png" width="40%"/> |
| 25 | +</p> |
23 | 26 |
|
24 | | -### Demo |
| 27 | +### Installation |
25 | 28 |
|
26 | | -Added an example project, with **iOS, watchOS** target: https://github.com/AppPear/ChartViewDemo |
| 29 | +It is a SPM package, in Xcode go to File -> Swift Packages -> Add Package Dependency and paste in the repo's url: https://github.com/AppPear/ChartView |
27 | 30 |
|
28 | | -## Line charts |
| 31 | +if you want to add previous releases you can find release tags https://github.com/AppPear/ChartView/releases |
29 | 32 |
|
30 | | -**LineChartView with multiple lines!** |
31 | | -First release of this feature, interaction is disabled for now, I'll figure it out how could be the best to interact with multiple lines with a single touch. |
32 | | - |
| 33 | +### Slack |
33 | 34 |
|
34 | | -Usage: |
35 | | -```swift |
36 | | -MultiLineChartView(data: [([8,32,11,23,40,28], GradientColors.green), ([90,99,78,111,70,60,77], GradientColors.purple), ([34,56,72,38,43,100,50], GradientColors.orngPink)], title: "Title") |
37 | | -``` |
38 | | -Gradient colors are now under the `GradientColor` struct you can create your own gradient by `GradientColor(start: Color, end: Color)` |
39 | | - |
40 | | -Available preset gradients: |
41 | | -* orange |
42 | | -* blue |
43 | | -* green |
44 | | -* blu |
45 | | -* bluPurpl |
46 | | -* purple |
47 | | -* prplPink |
48 | | -* prplNeon |
49 | | -* orngPink |
| 35 | +Join our Slack channel for day to day conversation and more insights: |
50 | 36 |
|
51 | | -**Full screen view called LineView!!!** |
| 37 | +https://join.slack.com/t/swiftuichartview/shared_invite/zt-g6mxioq8-j3iUTF1YKX7D23ML3qcc4g |
52 | 38 |
|
53 | | - |
| 39 | +## Quick start guide: |
54 | 40 |
|
55 | | -```swift |
56 | | - LineView(data: [8,23,54,32,12,37,7,23,43], title: "Line chart", legend: "Full screen") // legend is optional, use optional .padding() |
57 | | -``` |
| 41 | +**Create a simple chart:** |
58 | 42 |
|
59 | | -Adopts to dark mode automatically |
60 | | - |
61 | | - |
62 | | - |
63 | | -You can add your custom darkmode style by specifying: |
| 43 | +<p align="left"> |
| 44 | +<img src="Resources/chartpic1.png" width="350px"/> |
| 45 | +</p> |
64 | 46 |
|
65 | 47 | ```swift |
66 | | -let myCustomStyle = ChartStyle(...) |
67 | | -let myCutsomDarkModeStyle = ChartStyle(...) |
68 | | -myCustomStyle.darkModeStyle = myCutsomDarkModeStyle |
| 48 | +LineChart() |
| 49 | + .data([3, 5, 4, 1, 0, 2, 4, 1, 0, 2, 8]) |
| 50 | + .chartStyle(ChartStyle(backgroundColor: .white, foregroundColor: ColorGradient(.orange, .red))) |
69 | 51 | ``` |
70 | 52 |
|
71 | | -**Line chart is interactive, so you can drag across to reveal the data points** |
| 53 | +**Add a background grid to the chart:** |
72 | 54 |
|
73 | | -You can add a line chart with the following code: |
| 55 | +<p align="left"> |
| 56 | +<img src="Resources/chartpic2.png" width="350px"/> |
| 57 | +</p> |
74 | 58 |
|
75 | 59 | ```swift |
76 | | - LineChartView(data: [8,23,54,32,12,37,7,23,43], title: "Title", legend: "Legendary") // legend is optional |
| 60 | +ChartGrid { |
| 61 | + LineChart() |
| 62 | + .data([3, 5, 4, 1, 0, 2, 4, 1, 0, 2, 8]) |
| 63 | + .chartStyle(ChartStyle(backgroundColor: .white, foregroundColor: ColorGradient(.orange, .red))) |
| 64 | +} |
| 65 | +.setNumberOfHorizontalLines(5) |
| 66 | +.setNumberOfVerticalLines(4) |
77 | 67 | ``` |
78 | 68 |
|
79 | | -**Turn drop shadow off by adding to the Initialiser: `dropShadow: false`** |
80 | | - |
81 | | - |
82 | | -## Bar charts |
83 | | - |
| 69 | +**Add a axis label to the chart:** |
84 | 70 |
|
85 | | -**[New feature] you can display labels also along values and points for each bar to descirbe your data better!** |
86 | | -**Bar chart is interactive, so you can drag across to reveal the data points** |
87 | | - |
88 | | -You can add a bar chart with the following code: |
89 | | - |
90 | | -Labels and points: |
91 | | - |
92 | | -```swift |
93 | | - BarChartView(data: ChartData(values: [("2018 Q4",63150), ("2019 Q1",50900), ("2019 Q2",77550), ("2019 Q3",79600), ("2019 Q4",92550)]), title: "Sales", legend: "Quarterly") // legend is optional |
94 | | -``` |
95 | | -Only points: |
| 71 | +<p align="left"> |
| 72 | +<img src="Resources/chartpic3.png" width="350px"/> |
| 73 | +</p> |
96 | 74 |
|
97 | 75 | ```swift |
98 | | - BarChartView(data: ChartData(points: [8,23,54,32,12,37,7,23,43]), title: "Title", legend: "Legendary") // legend is optional |
| 76 | +AxisLabels { |
| 77 | + ChartGrid { |
| 78 | + LineChart() |
| 79 | + .data([3, 5, 4, 1, 0, 2, 4, 1, 0, 2, 8]) |
| 80 | + .chartStyle(ChartStyle(backgroundColor: .white, foregroundColor: ColorGradient(.orange, .red))) |
| 81 | + } |
| 82 | + .setNumberOfHorizontalLines(5) |
| 83 | + .setNumberOfVerticalLines(4) |
| 84 | +} |
| 85 | +.setAxisXLabels([(1, "Nov"), (2, "Dec"), (3, "Jan")], range: 1...3) |
99 | 86 | ``` |
100 | 87 |
|
101 | | -**ChartData** structure |
102 | | -Stores values in data pairs (actually tuple): `(String,Double)` |
103 | | -* you can have duplicate values |
104 | | -* keeps the data order |
105 | | - |
106 | | -You can initialise ChartData multiple ways: |
107 | | -* For integer values: `ChartData(points: [8,23,54,32,12,37,7,23,43])` |
108 | | -* For floating point values: `ChartData(points: [2.34,3.14,4.56])` |
109 | | -* For label,value pairs: `ChartData(values: [("2018 Q4",63150), ("2019 Q1",50900)])` |
| 88 | +**Show chart marks on the line:** |
110 | 89 |
|
111 | | - |
112 | | -You can add different formats: |
113 | | -* Small `ChartForm.small` |
114 | | -* Medium `ChartForm.medium` |
115 | | -* Large `ChartForm.large` |
| 90 | +<p align="left"> |
| 91 | +<img src="Resources/chartpic4.png" width="350px"/> |
| 92 | +</p> |
116 | 93 |
|
117 | 94 | ```swift |
118 | | -BarChartView(data: ChartData(points: [8,23,54,32,12,37,7,23,43]), title: "Title", form: ChartForm.small) |
| 95 | +AxisLabels { |
| 96 | + ChartGrid { |
| 97 | + LineChart() |
| 98 | + .showChartMarks(true) |
| 99 | + .data([3, 5, 4, 1, 0, 2, 4, 1, 0, 2, 8]) |
| 100 | + .chartStyle(ChartStyle(backgroundColor: .white, foregroundColor: ColorGradient(.orange, .red))) |
| 101 | + } |
| 102 | + .setNumberOfHorizontalLines(5) |
| 103 | + .setNumberOfVerticalLines(4) |
| 104 | +} |
| 105 | +.setAxisXLabels([(1, "Nov"), (2, "Dec"), (3, "Jan")], range: 1...3) |
119 | 106 | ``` |
120 | 107 |
|
121 | | -For floating point numbers, you can set a custom specifier: |
| 108 | +**Apply custom ranges on chart** |
122 | 109 |
|
123 | | -```swift |
124 | | -BarChartView(data: ChartData(points:[1.23,2.43,3.37]) ,title: "A", valueSpecifier: "%.2f") |
125 | | -``` |
126 | | -For integers you can disable by passing: `valueSpecifier: "%.0f"` |
127 | | - |
128 | | - |
129 | | -You can set your custom image in the upper right corner by passing in the initialiser: `cornerImage:Image(systemName: "waveform.path.ecg")` |
130 | | - |
131 | | - |
132 | | - **Turn drop shadow off by adding to the Initialiser: `dropShadow: false`** |
133 | | - |
134 | | - ### You can customize styling of the chart with a ChartStyle object: |
135 | | - |
136 | | -Customizable: |
137 | | -* background color |
138 | | -* accent color |
139 | | -* second gradient color |
140 | | -* text color |
141 | | -* legend text color |
142 | | - |
143 | | -```swift |
144 | | - let chartStyle = ChartStyle(backgroundColor: Color.black, accentColor: Colors.OrangeStart, secondGradientColor: Colors.OrangeEnd, chartFormSize: ChartForm.medium, textColor: Color.white, legendTextColor: Color.white ) |
145 | | - ... |
146 | | - BarChartView(data: [8,23,54,32,12,37,7,23,43], title: "Title", style: chartStyle) |
147 | | -``` |
| 110 | +<p align="left"> |
| 111 | +<img src="Resources/chartpic5.png" width="350px"/> |
| 112 | +</p> |
148 | 113 |
|
149 | | -You can access built-in styles: |
150 | 114 | ```swift |
151 | | - BarChartView(data: [8,23,54,32,12,37,7,23,43], title: "Title", style: Styles.barChartMidnightGreen) |
| 115 | +AxisLabels { |
| 116 | + ChartGrid { |
| 117 | + LineChart() |
| 118 | + .showChartMarks(true) |
| 119 | + .data([3, 5, 4, 1, 0, 2, 4, 1, 0, 2, 8]) |
| 120 | + .rangeY(0...10) |
| 121 | + .rangeX(0...5) |
| 122 | + .chartStyle(ChartStyle(backgroundColor: .white, foregroundColor: ColorGradient(.orange, .red))) |
| 123 | + } |
| 124 | + .setNumberOfHorizontalLines(5) |
| 125 | + .setNumberOfVerticalLines(4) |
| 126 | +} |
| 127 | +.setAxisXLabels([(1, "Nov"), (2, "Dec"), (3, "Jan")], range: 1...3) |
152 | 128 | ``` |
153 | | -#### All styles available as a preset: |
154 | | -* barChartStyleOrangeLight |
155 | | -* barChartStyleOrangeDark |
156 | | -* barChartStyleNeonBlueLight |
157 | | -* barChartStyleNeonBlueDark |
158 | | -* barChartMidnightGreenLight |
159 | | -* barChartMidnightGreenDark |
160 | | - |
161 | | - |
162 | | - |
163 | | - |
164 | 129 |
|
| 130 | +**Add multiple charts in the same frame** |
165 | 131 |
|
166 | | -### You can customize the size of the chart with a ChartForm object: |
167 | | - |
168 | | -**ChartForm** |
169 | | -* `.small` |
170 | | -* `.medium` |
171 | | -* `.large` |
172 | | -* `.detail` |
| 132 | +<p align="left"> |
| 133 | +<img src="Resources/chartpic6.png" width="350px"/> |
| 134 | +</p> |
173 | 135 |
|
174 | 136 | ```swift |
175 | | -BarChartView(data: [8,23,54,32,12,37,7,23,43], title: "Title", form: ChartForm.small) |
| 137 | +AxisLabels { |
| 138 | + ChartGrid { |
| 139 | + LineChart() |
| 140 | + .showChartMarks(true) |
| 141 | + .data([3, 5, 4, 1, 0, 2, 4, 1, 0, 2, 8]) |
| 142 | + .rangeY(0...12) |
| 143 | + .rangeX(0...5) |
| 144 | + .chartStyle(ChartStyle(backgroundColor: .white, foregroundColor: ColorGradient(.orange, .red))) |
| 145 | + LineChart() |
| 146 | + .showChartMarks(true) |
| 147 | + .data([4, 1, 0, 2, 8, 3, 6, 1, 4]) |
| 148 | + .rangeY(0...12) |
| 149 | + .rangeX(0...5) |
| 150 | + .chartStyle(ChartStyle(backgroundColor: .white, foregroundColor: ColorGradient(.blue, .purple))) |
| 151 | + } |
| 152 | + .setNumberOfHorizontalLines(5) |
| 153 | + .setNumberOfVerticalLines(4) |
| 154 | +} |
| 155 | +.setAxisXLabels([(1, "Nov"), (2, "Dec"), (3, "Jan")], range: 1...3) |
176 | 156 | ``` |
177 | 157 |
|
178 | | -### WatchOS support for Bar charts: |
179 | | - |
180 | | - |
| 158 | +**Combine chart types in the same frame** |
181 | 159 |
|
182 | | -## Pie charts |
183 | | - |
184 | | - |
185 | | -You can add a pie chart with the following code: |
| 160 | +<p align="left"> |
| 161 | +<img src="Resources/chartpic7.png" width="350px"/> |
| 162 | +</p> |
186 | 163 |
|
187 | 164 | ```swift |
188 | | - PieChartView(data: [8,23,54,32], title: "Title", legend: "Legendary") // legend is optional |
| 165 | +AxisLabels { |
| 166 | + ChartGrid { |
| 167 | + BarChart() |
| 168 | + .data([2, 4, 1, 3]) |
| 169 | + .chartStyle(ChartStyle(backgroundColor: .white, foregroundColor: ColorGradient(.orange, .red))) |
| 170 | + LineChart() |
| 171 | + .showChartMarks(true) |
| 172 | + .data([2, 4, 1, 3]) |
| 173 | + .chartStyle(ChartStyle(backgroundColor: .white, foregroundColor: ColorGradient(.blue, .purple))) |
| 174 | + } |
| 175 | + .setNumberOfHorizontalLines(5) |
| 176 | + .setNumberOfVerticalLines(4) |
| 177 | +} |
| 178 | +.setAxisXLabels([(1, "Nov"), (2, "Dec"), (3, "Jan")], range: 1...3) |
189 | 179 | ``` |
190 | 180 |
|
191 | | -**Turn drop shadow off by adding to the Initialiser: `dropShadow: false`** |
192 | | - |
0 commit comments