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