Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.3k views
in Technique[技术] by (71.8m points)

swift - SwiftUI macOS view starts lagging when displaying multiple charts

I am displaying multiple charts in a view.
The charts are just paths in a frame and data comes from an csv file (not bigger than 400mb).
Those charts are displayed inside of a LazyVGrid and the whole view is inside a scroll view.

Loading the view takes about 10 - 20 seconds, but when I start scrolling through the charts, it becomes very laggy.
To solve this I tried to attach .drawingGroup() to the chart views, but there where nearly no performance change.

the code looks something like this:

import SwiftUI


struct GroupView: View {

@State var chartData = [CGFloat]()

  let columns = [
        GridItem(.adaptive(minimum: 720))
 
       ]
    

  var body: some View {

VStack{

 ScrollView {
                
   LazyVGrid(columns: columns){

     CSVChart(data: chartData, chartName: String, x-yaxisName: [String](), lineColor: CGColor)
        .frame(width: 700, height: 300, alignment: .center)
        .drawingGroup() // there is as well no performance change when .drawingGroup()  is inside the chart view

        }

     
    }

}.onAppear{
   
 chartData = // get csv data logic

   }



}
}



I know that the csv file is quite large, and that this will cause the slow behaviour, but I thought that other apps aren't that laggy when working with large files so this might be fixable.
It would be great if someone could help me with this problem.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...