Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.8k 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 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...