SwiftUI Charts with custom styles

Overview

SwiftUI Charts

Build custom charts with SwiftUI

Styles

Line

Chart(data: [0.1, 0.3, 0.2, 0.5, 0.4, 0.9, 0.1])
    .chartStyle(
        LineChartStyle(.quadCurve, lineColor: .blue, lineWidth: 5)
    )

Area

Chart(data: [0.1, 0.3, 0.2, 0.5, 0.4, 0.9, 0.1])
    .chartStyle(
        AreaChartStyle(.quadCurve, fill:
            LinearGradient(gradient: .init(colors: [Color.blue.opacity(0.2), Color.blue.opacity(0.05)]), startPoint: .top, endPoint: .bottom)
        )
    )

Stacked Area

Chart(data: matrix)
    .chartStyle(
        StackedAreaChartStyle(.quadCurve, colors: [.yellow, .orange, .red])
    )

Column

Chart(data: [0.1, 0.3, 0.2, 0.5, 0.4, 0.9, 0.1])
    .chartStyle(
        ColumnChartStyle(column: Capsule().foregroundColor(.green), spacing: 2)
    )

Stacked Column

Chart(data: matrix)
    .chartStyle(
        StackedColumnChartStyle(spacing: 2, colors: [.yellow, .orange, .red])
    )

Roadmap

  • Bar chart style

Code Contributions

Feel free to contribute via fork/pull request to master branch. If you want to request a feature or report a bug please start a new issue.

Comments
  • ColumnChartStyle reverses data

    ColumnChartStyle reverses data

    I am on version 1.0. The ChartStyle influences the order of the input data as you can see in the screenshot.

    As this is kind of unintuitive and I couldn't find any note that/why it is done this way I guess it's a bug.

    image

    opened by theMomax 4
  • Line charts upside down on WidgetKit

    Line charts upside down on WidgetKit

    Depending on what your use-case desires: line charts out of the box will be upside down on widgets. To solve this remove all instances of rotationEffects -- and animations for good measure.

            //.rotationEffect(.degrees(180), anchor: .center)
            //.rotation3DEffect(.degrees(180), axis: (x: 0, y: 1, z: 0))
    
    opened by skg54 1
  •  Showing All Messages : The remote repository could not be accessed.

    Showing All Messages : The remote repository could not be accessed.

    Hello. I get this error with your repository:

    Showing All Messages : The remote repository could not be accessed. Make sure a valid repository exists at the specified location and that the correct credentials have been supplied.

    opened by veleskevich 1
  • Fix stacked area chart order issue

    Fix stacked area chart order issue

    There may be some issues in the StackedAreaChartStyle. I've tried the code below:

    struct StackedAreaChartDemo: View {
        private let matrixData: [[CGFloat]] = [[0.0, 0.2, 0.3], [0.3, 0.3, 0.3], [0.6, 0.2, 0.0]]
        
        var body: some View {
            Chart(data: matrixData)
                .chartStyle(
                    StackedAreaChartStyle(.quadCurve, colors: [.yellow, .orange, .red])
                )
                .background(
                    Color.gray.opacity(0.1)
                        .overlay(
                            GridPattern(verticalLines: matrixData.count)
                                .inset(by: 1)
                                .stroke(Color.red.opacity(0.2), style: .init(lineWidth: 1, lineCap: .round))
                        )
                )
                .cornerRadius(16)
                .padding()
        }
    }
    

    Which returns:

    截屏2021-08-23 下午4 29 13

    I think it is a horizontal flipped of the correct chart:

    截屏2021-08-23 下午4 28 33

    I've checked out the implementation of StackedAreaChartStyle. There is no need to do multiple reversed operations to the original data. Simply transpose the data matrix will do the job. In the end, use the zIndex to put layers into correct order.

    opened by beader 0
  • Updates

    Updates

    • Adding a Bar chart style

    • Allowing negative values in the column chart

    • Adding a time series chart

    • Simplifying time series

    Co-authored-by: Alexander Heinrich [email protected] Co-authored-by: Alexander Heinrich [email protected]

    opened by ay42 0
  • y-mirrored area chart; fill support for stacked area

    y-mirrored area chart; fill support for stacked area

    Y-mirroring is to display a chart upside-down, handy for displaying negative area data. See the dual stacked area demo chart.

    Fill support for area charts, while retaining backwards compatibility.

    I hope the proposed changes make sense and are useful!

    opened by reedes 0
  • Labels for Max Value

    Labels for Max Value

    Hi @spacenation,

    first of all, thanks for providing this amazing library! Is there a way to add label for the largest (and maybe smallest) value to the left of a chart? That'd be really helpful for most of my use cases.

    Thanks and best regards Toni

    opened by xremix 1
  • How to

    How to "zoom" or "scale"

    Suppose I have value set of values that fluctuate between 0 and 1. The timeline goes up and down (lowest value 0) correctly. Now suppose my next value is 50. I would like the timeline to "zoom out" (or "scale up") so that to place the next incoming value on screen proportinate to the previous numbers. There is no way to know in advance what value I will receive next, it maybe be a negative value or some higher number as 500.

    Is there a built-in solution for this? If not, how could I go about it? Many thanks.

    opened by svoip 0
  • How to add the label on each curve point of chart

    How to add the label on each curve point of chart

    Hi i am new to swiftui , i really like your chart but how to add lables on each pickpoints of chart

    Chart(data: [0.0, 0.2, 0.5, 0.4, 0.3, 0.5, 0.1]) .chartStyle( AreaChartStyle(.quadCurve, fill: LinearGradient(gradient: .init(colors: [Color.orange.opacity(0.7), Color.orange.opacity(0.7)]), startPoint: .top, endPoint: .leading) )

                )
    

    I want to show lable of each curve point of label

    Thanks

    opened by Annyjain29 0
Releases(1.1.0)
Owner
SpaceNation
Distributed software development team
SpaceNation
An overview of the different types of charts you can make with Swift Charts

Swift Charts Examples This repo aims to provide sample code for lots of different chart types for you to use as inspiration for your own projects. We

Jordi Bruin 1.2k Dec 30, 2022
🎉 SwiftUI stock charts for iOS

SwiftUI Stock Charts Display interactive stock charts easily ?? Instalation In Xcode go to File -> Swift packages -> Add package dependency Copy and p

Dennis Concepción Martín 94 Dec 26, 2022
🎉 SwiftUI stock charts for iOS

?? SwiftUI stock charts for iOS

Dennis Concepción Martín 94 Dec 26, 2022
SwiftUICharts - A charts / plotting library for SwiftUI.

A charts / plotting library for SwiftUI. Works on macOS, iOS, watchOS, and tvOS and has accessibility features built in.

Will Dale 632 Jan 3, 2023
Beautiful charts for iOS/tvOS/OSX! The Apple side of the crossplatform MPAndroidChart.

One more heads up: As Swift evolves, if you are not using the latest Swift compiler, you shouldn't check out the master branch. Instead, you should go to the release page and pick up whatever suits you.

Daniel Cohen Gindi 26.3k Jan 3, 2023
SwiftCharts - Easy to use and highly customizable charts library for iOS

SwiftCharts Easy to use and highly customizable charts library for iOS Features: Bars - plain, stacked, grouped, horizontal, vertical Scatter Lines (s

Ivan Schütz 2.4k Jan 4, 2023
A powerful 🚀 Android chart view / graph view library, supporting line- bar- pie- radar- bubble- and candlestick charts as well as scaling, panning and animations.

⚡ A powerful & easy to use chart library for Android ⚡ Charts is the iOS version of this library Table of Contents Quick Start Gradle Maven Documentat

Philipp Jahoda 36k Jan 5, 2023
An iOS wrapper for ChartJS. Easily build animated charts by leveraging the power of native Obj-C code.

TWRCharts TWRCharts An Obj-C wrapper for ChartJS. Easily build animated charts by leveraging the power of native code. TWRCharts is yet another charti

Michelangelo Chasseur 363 Nov 28, 2022
Light weight charts view generater for iOS. Written in Swift.

# ###Light weight charts view generater for iOS. Written in Swift. Requirements iOS 8.0+ XCode 7.3+ Installation CocoaPods $ pod init specify it in yo

Recruit Holdings. Media Technology Lab 982 Nov 16, 2022
Easy to use and highly customizable pie charts library for iOS

PieCharts Easy to use and highly customizable pie charts library for iOS Swift 4.2, iOS 8+ Video Features: Customizable slices Add overlays using simp

null 503 Dec 6, 2022
Core Charts | Basic Scrollable Chart Library for iOS

Core Charts | Basic Chart Library for iOS HCoreBarChart VCoreBarChart Requirements Installation Usage Appearance Customization Getting Started You nee

Çağrı ÇOLAK 71 Nov 17, 2022
Health Sample app using Swift, RxSwift, Anchorage, Charts

HealthSample First run pod install, then build the project and run in your devices or simulators. This project has used RIBs, Swift, RxSwift, Anchorag

null 4 Feb 11, 2022
FLCharts: Easy to use and highly customizable charts library for iOS

FLCharts Requirements Xcode 11 / Swift 5 iOS >= 11.0 Installation FLCharts is av

Francesco Leoni 250 Dec 26, 2022
Beautiful charts for iOS/tvOS/OSX! The Apple side of the crossplatform MPAndroidChart.

Version 4.0.0, synced to MPAndroidChart #f6a398b Just a heads up: Charts 3.0 has some breaking changes. Please read the release/migration notes. Anoth

Daniel Cohen Gindi 26.3k Jan 8, 2023
Aplikasi iOS kasus Covid-19 di U.S dengan Storyboard, Framework Charts dari danielgindi, dan API dari covidtracking.com

Aplikasi iOS kasus Covid-19 di U.S dengan Storyboard, Framework Charts dari danielgindi, dan API dari covidtracking.com

DK 7 Aug 1, 2022
Using Swift Charts and Voiceover Chart Descriptor to compose music. 🤯

Chart de lune ?? Using Swift Charts and Voiceover Chart Descriptor to compose music. ?? Image source: https://hadikarimi.com/portfolio/claude-debussy-

An Trinh 31 Nov 21, 2022
Easy to use and highly customizable pie charts library for iOS

PieCharts Easy to use and highly customizable pie charts library for iOS Swift 4.2, iOS 8+ Video Features: Customizable slices Add overlays using simp

null 503 Dec 6, 2022
FlowerChart - custom chart written in Swift

FlowerChart - custom chart written in Swift Fully vector flower-shaped chart written in Swift Flower-shaped chart written in Swift, this repo is a sam

Alexander Telegin 15 Jun 9, 2021