问题描述
关于基本chartjs线图 https://www.chartjs.org/samples/latest/charts/line/basic.html 单击“随机化数据”按钮后,图表会进行动画处理(即平滑渲染)。
但是这里的时间序列图 https://www.chartjs.org/samples/latest/scales/time/financial.html 单击“更新”按钮时,渲染不流畅。
如何在时间序列图上实现平滑渲染。
谢谢。
解决方法
要获得平滑的渲染效果,您需要定义/增加import UIKit
class ViewController: UIViewController {
@IBOutlet weak var tableView: UITableView!
@IBOutlet weak var searchBar: UISearchBar!
var data = ["Apple","Microsoft","Twitter","Facebook","Instagram"]
var filteredData = [String]()
var isSearching = false
override func viewDidLoad() {
super.viewDidLoad()
searchBar.delegate = self
tableView.dataSource = self
searchBar.enablesReturnKeyAutomatically = false
tableView.keyboardDismissMode = .onDrag
}
}
extension ViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView,numberOfRowsInSection section: Int) -> Int {
if isSearching {
return filteredData.count
} else {
return data.count
}
}
func tableView(_ tableView: UITableView,cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell",for: indexPath)
if isSearching {
cell.textLabel?.text = filteredData[indexPath.row]
} else {
cell.textLabel?.text = data[indexPath.row]
}
return cell
}
}
extension ViewController: UISearchBarDelegate {
func searchBar(_ searchBar: UISearchBar,textDidChange searchText: String) {
if searchBar.text == "" {
isSearching = false
tableView.reloadData()
} else {
isSearching = true
filteredData = data.filter({$0.contains(searchBar.text ?? "")})
tableView.reloadData()
}
}
}
选项。
animation.duration
duration
:动画花费的毫秒数。