jordibruin / Swift-Charts-Examples

An overview of the different types of charts you can make with Swift Charts
MIT License
1.95k stars 126 forks source link

Scrolling CPU % utilization type graph #96

Closed nsmith1024 closed 1 year ago

nsmith1024 commented 1 year ago

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

atrinh0 commented 1 year ago

The Sound Bar chart uses sound from your microphone to produce a value, this graph animates with time and might achieve what you wanted.

Basically it is a matter of updating the data source but truncating the results to the latest number of data points you required.

nsmith1024 commented 1 year ago

Thanks for the info, i was talking about something like shown in this video

https://www.youtube.com/watch?v=N3hiSV-B4v0

atrinh0 commented 1 year ago

Making the following changes to the Sound Bar chart achieves something similar.

private var chart: some View {
        Chart(data, id: \.self) { sample in
            let index = data.firstIndex(of: sample) ?? 0
            LineMark(
                x: .value("Index", index),
                y: .value("Value", sample.sample)
            )
            .interpolationMethod(.catmullRom)

https://user-images.githubusercontent.com/16542463/212486489-428c55b7-3be9-43b8-8961-443d75904058.mp4