Skip to content

JiningLiu/StockCharts

ย 
ย 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

StockCharts (SwiftUI)

Build Status

This package is for iOS 14+, if your app only needs to support iOS 16 or above, please see Swift Charts

Display interactive stock charts easily ๐ŸŽ‰

Instalation

  • In Xcode go to File -> Swift packages -> Add package dependency
  • Copy and paste https://github.com/JiningLiu/StockCharts.git

Demo app

Trades is a SwiftUI app with real use cases of the StockCharts framework. This demo app is based on the original stock-charts framework, a demo app for this fork is coming soon.

Usage

A wiki page for this framework is coming soon.

import StockCharts

Line chart

let lineChartController = LineChartController(prices: [Double])
LineChartView(lineChartController: lineChartController)

You can customise the line chart with LineChartController

LineChartController(
    prices: [Double],
    dates: [String]? = nil,
    hours: [String]? = nil,
    dateFormat: String = "yy-MM-dd",
    
    labelColor: Color = .blue,
    labelDateFormat: DateFormatter.Style = .medium,
    indicatorPointColor: Color = .blue,
    showingIndicatorLineColor: Color = .blue,
    flatTrendLineColor: Color = .purple,
    uptrendLineColor: Color = .green,
    downtrendLineColor: Color = .red,
    
    dragGesture: Bool = false,
    dragGestureMinimumDuration: Double = 0
)

To enable the drag gesture set dragGesture to true in the LineChartController

LineChartView(
    lineChartController:
        LineChartController(
            prices: [Double],
            dragGesture: true
        )
)

LineChartVideo

Capsule chart

CapsuleChartView(percentageOfWidth: CGFloat)
// percentageOfWidth: must be 0 <= x <= 1

Example

import SwiftUI
import StockCharts

struct ContentView: View {
    var body: some View {
        RoundedRectangle(cornerRadius: 25)
            .frame(width: 400, height: 120)
            .foregroundColor(.white)
            .shadow(color: Color(.gray).opacity(0.15), radius: 10)
            .overlay(
                VStack(alignment: .leading) {
                    Text("Dennis Concepcion")
                        .font(.title3)
                        .fontWeight(.semibold)
                    
                    Text("Random guy")
                    
                    CapsuleChartView(percentageOfWidth: 0.6, style: CapsuleChartStyle(capsuleColor: Color.blue))
                        .padding(.top)
                }
                .padding()
            )
    }
}

CapsuleChart