128
|
1 # stock-charts
|
127
|
2
|
129
|
3 <a href="https://www.producthunt.com/posts/stockcharts-for-swiftui?utm_source=badge-featured&utm_medium=badge&utm_souce=badge-stockcharts-for-swiftui" target="_blank"><img src="https://api.producthunt.com/widgets/embed-image/v1/featured.svg?post_id=295975&theme=dark" alt="StockCharts for SwiftUI - Display interactive stock charts easily 🎉 | Product Hunt" style="width: 250px; height: 54px;" width="250" height="54" /></a>
|
|
4
|
131
|
5 This project is now deprecated in favor of the [Apple’s native
|
|
6 framework](https://developer.apple.com/documentation/charts). At the time of
|
|
7 archiving this project, it has accumulated 98 stars and 11 forks on Github.
|
129
|
8
|
|
9 StockCharts is a library to create intertactive charts in SwiftUI.
|
|
10
|
|
11 ## Installation
|
|
12 In Xcode go to File -> Swift packages -> Add package dependency
|
|
13 Copy and paste https://github.com/denniscmartin/stock-charts.git
|
131
|
14 I’ve created a demo app using StockCharts called Trades. Check out the code in
|
|
15 my Github
|
129
|
16
|
|
17 ## Usage
|
|
18
|
|
19 ```swift
|
|
20 import StockCharts
|
|
21 ```
|
|
22
|
|
23 ### Line chart
|
|
24
|
|
25 ```swift
|
|
26 let lineChartController = LineChartController(prices: [Double])
|
|
27 LineChartView(lineChartController: lineChartController)
|
|
28 ```
|
|
29
|
|
30 You can customise the line chart with LineChartController
|
|
31
|
|
32 ```swift
|
|
33 LineChartController(
|
|
34 prices: [Double],
|
|
35 dates: [String]?, // format: yy-MM-dd
|
|
36 hours: [String]?, // has to correspond to dates
|
|
37 labelColor: Color,
|
|
38 indicatorPointColor: Color,
|
|
39 showingIndicatorLineColor: Color,
|
|
40 flatTrendLineColor: Color,
|
|
41 uptrendLineColor: Color,
|
|
42 downtrendLineColor: Color,
|
|
43 dragGesture: Bool
|
|
44 )
|
|
45 ```
|
127
|
46
|
129
|
47 To enable the drag gesture set dragGesture to true in the LineChartController
|
|
48
|
|
49 ```swift
|
|
50 LineChartView(
|
|
51 lineChartController:
|
|
52 LineChartController(
|
|
53 prices: [Double],
|
|
54 dragGesture: true
|
|
55 )
|
|
56 )
|
|
57 ```
|
|
58
|
|
59 ### Capsule chart
|
|
60
|
|
61 ```swift
|
|
62 CapsuleChartView(percentageOfWidth: CGFloat)
|
|
63 // percentageOfWidth: must be 0 <= x <= 1
|
|
64 import SwiftUI
|
|
65 import StockCharts
|
127
|
66
|
129
|
67 struct ContentView: View {
|
|
68 var body: some View {
|
|
69 RoundedRectangle(cornerRadius: 25)
|
|
70 .frame(width: 400, height: 120)
|
|
71 .foregroundColor(.white)
|
|
72 .shadow(color: Color(.gray).opacity(0.15), radius: 10)
|
|
73 .overlay(
|
|
74 VStack(alignment: .leading) {
|
|
75 Text("Dennis Concepcion")
|
|
76 .font(.title3)
|
|
77 .fontWeight(.semibold)
|
|
78
|
|
79 Text("Random guy")
|
|
80
|
|
81 CapsuleChartView(percentageOfWidth: 0.6, style: CapsuleChartStyle(capsuleColor: Color.blue))
|
|
82 .padding(.top)
|
|
83 }
|
|
84 .padding()
|
|
85 )
|
|
86 }
|
|
87 }
|
131
|
88 ```
|