Giter Site home page Giter Site logo

swift-charts-examples's Introduction

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 start by recreating the sample charts Apple uses in their sessions related to Swift Charts. The goal is to make each chart type customizable, accessible and flexible so that you can easily change it to your needs.

image

Todo

  • Add missing Charts
  • Multi-language Support
  • First row, second bar with the lines with blocks in the middle
  • Sleep stages chart
  • iPhone battery percentage screen with different colors and overlaid bar
  • Make all charts (even more) accessible

See the open issues if you think anything is missing from this list. You can also contact me on Twitter if you have any suggestions or feedback.

How to add a new chart

Each chart needs a preview chart as well as a detail view. The preview chart is used in the home screen of the app for easier navigation. Look at the Simple Line Chart code to see what the format should be for the preview charts. On the detail view, make sure you add some customisation options in a separate section from the chart. If you have any questions feel free to create an issue.

Source: https://developer.apple.com/videos/play/wwdc2022/10137/

Chart Types

Electrocardiograms (ECG)

iPhone Storage

Screen Time

Line Chart

Line Chart with Lollipop

Animating Line

Line with changing gradient

Line Charts

Line Point

Single Bar

Single Bar with Threshold Rule Mark

Two Bars

Pyramid

Time Sheet Bar

Sound Bar

Horizontal Scrolling Bar Chart

Area Chart

Stacked Area Chart

Range Chart

Heart Rate Range Chart

Candle Stick Chart

Customizable Heat Map

GitHub Contributions Graph

Scatter Chart

Vector Field

Other Example Repos

Check out my other example repos

🪧 TipKit

🏝️ Dynamic Island

🥽 visionOS

swift-charts-examples's People

Contributors

aaronpearce avatar alexfringes avatar aoverholtzer avatar atrinh0 avatar auramagi avatar brennanmke avatar dariusngo avatar elichartnett avatar hulk510 avatar jordibruin avatar lekawik avatar mathewa6 avatar melgu avatar nunogoncalves avatar panpapryk avatar shiftingsand avatar stewartlynch avatar theedov avatar thurss4 avatar tommy-holmes avatar tunous avatar vibrazy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swift-charts-examples's Issues

Doesn't compile for macOS

The Build.xcconfig file contains macOS as a viable target. When trying to build for macOS though, there are 46 errors because there is a lot of iOS-specific code

Couldn't load project.

I downloaded the project and try to open Swift Charts Examples. xcworkspace.
But I can't see anything. Please refer image below.

Screenshot 2022-11-29 at 10 01 51

Is anyone else noticing the app lagging?

Is it just Xcode being Xcode, or the sample app is becoming laggy with all those charts? Testing on a simulator since I don't have iOS16 Beta installed.

Screen.Recording.2022-06-15.at.9.56.13.am.mov

Weird Redrawing of Chart

I have been playing around with SingleLineLollipop.swift and noticed this weird redrawing behavior. I set a break point on line 42 and then run the example on my device/sim ( either doesn't matter ). Every time I touch the screen and drag, the break point gets triggered and the app pauses. At first I thought, ok this makes sense, the selectedElement state var updates, and the chart needs to redraw the chartBackground. No problem. But as you can imagine this isn't ideal... for large data sets I noticed there is a delay / animation hitch when the user drags her finger across the chart. So I thought to extract the state var and the chartBackground to a separate view. But no matter how I extract them, the chart ALWAYS redraws. How can I create a view like you have in the chart background that has data about the x value the user is currently touching and have it update without the whole chart updating?

Candle Stick Chart performance and lollipop placement

Upon dragging over the Candle Stick Chart to move the lollipop, it feels sluggish, also when moving to the left edge and right edges of the chart, the lollipop placement is off the chart (pun intended).

Compared to the lollipop from the Apple implementation of Line Chart with Lollipop the performance and range edges are not an issue.

Simulator Screen Shot - iPhone 13 Pro Max - 2022-06-23 at 18 10 07

Scrolling CPU % utilization type graph

Hello,

I need a script chart type graph, similar to the one in windows task manager that shows a scrolling graph of CPU utilization over time.

Do you have something like that?

Where it only plots the last several data points, and scrolls over as each new point is added, sort of like a electrocardiogram, or a heart rate monitor where only the last few data points are kept and plotted in an infinitely scrolling one way graph.

Thanks

The project doesn't compile.

Just to be sure I didn't do something incorrectly I cloned the project from scratch into a junk directory. I got the same compile error.

image

Add a scrolling graph

The Apple Health app contains a graph that you can scroll. I think this would also be a good use case to implement.

I have no clue where to start yet, but maybe we can figure something out.

RPReplay_Final1657032449.MP4

Standardise customisation across charts

It would be great to have a standard list of customisable options per chart. A new chart template or something could be nice as well so that people can copy that in, and then start adding their code.

Make all charts accessible

Adding simple accessibility labels and values goes a long way in making it the standard for people when they use these charts as examples.

Please add these to your sample charts:
.accessibilityLabel("(element.ageRange)")
.accessibilityValue("(element.percentage)")

Convert all charts to use the isOverview pattern

To show the chart in the overview page and on the detail page, we should switch between how they are displayed according to a boolean. Some charts already implement this like the SingleLineLollipop. It would be nice to have a consistent way across the project to handle this.

image

Sleep stages graph

I was implementing the Sleep Stages (Awake, REM, Core, Deep) graph using the BarMark. The plot matches that of the Apple's Health App, but I could not manage to put the connecting lines as shown in the Apple Health app. Can anybody tell me how to implement the connecting lines between Bar Marks.

Apple Health App
mine

Add combine charts

Can we add multiple charts in a view?
Display all charts on the same view and coordinate system is unified

MarkDimension not working as expected. Someone an idea? Is this a bug?

I tried to add the bottom right chart to the repo but there seems to be bugs in the beta 1.

Reading the documentation of MarkDimension, I assume that using .inset(0) should fill the step size. If I understand it correctly this should result in rectangles next to each other filling the whole space, as desired.
Screenshot 2022-06-16 at 22 40 48

But when I create a chart like this:

Chart(data) { rectData in
  RectangleMark(x: .value("x", rectData.a),
                y: .value("y", rectData.b),
                width: .inset(0),
                height: .inset(0))
  .foregroundStyle(by: .value("Value", rectData.value))
}

the result is an empty chart:

Screenshot 2022-06-16 at 22 46 12

I get it to work with the following code (works but uses hard-coded values for the step size):

Chart(data) { rectData in
  RectangleMark(xStart: .value("minA", rectData.a),
                xEnd: .value("maxA", rectData.a + 1),
                yStart: .value("minB", rectData.b),
                yEnd: .value("minB", rectData.b + 1.0))
    .foregroundStyle(by: .value("Value", rectData.value))
}

The result:

Screenshot 2022-06-16 at 22 48 29

Do I misunderstand .inset(_:)?

By the way, .ratio(1) doesn't work as well.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.