- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
以下基于 LineChartView
示例 ( from youtube ),它在标准 View (单 View 应用程序)中运行良好,而 BarChartView
在 TableViewCell
使用与下面所示相同的习惯用法。我有一个每两秒到期的时间来更新单元格,但尚未连接。
x,y 轴生成正确(最终图形仅显示 9 个单元格中的 2 个),只是没有绘制点。但是,失败仅发生在 LineChartView
中。我查看了有关此问题的其他引用资料,但尚未找到我的具体修复方法。有什么想法吗?
TableViewController
class GraphTableTableViewController: UITableViewController {
let model = [1,2,3,4,5,6,7,8,9]
var timer: Timer? = nil
var noSamples = 0
override func viewDidLoad() {
super.viewDidLoad()
timer = Timer.scheduledTimer(timeInterval: 2.0, target: self, selector: #selector(fireTimer), userInfo: nil, repeats: true)
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return model.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "lineChart_cell", for: indexPath)
let graphCell = cell as? LineGraphCell
graphCell!.setChartValues()
print("\(model[indexPath.row])")
return graphCell!
}
@objc func fireTimer() {
print("Timer Fired")
noSamples += 1
(view as? UITableView)?.reloadData()
}
}
TableViewCell 实现如下所示:
class LineGraphCell: UITableViewCell {
@IBOutlet weak var lineChart: LineChartView!
let x = [0,1,2,3,4,5,6,7,8,9]
let y = [0,1,2,3,4,5,6,7,8,9]
func setChartValues() {
var values = [ChartDataEntry]()
for index in x {
let value = ChartDataEntry(x: Double(index), y: Double(y[index]))
values.append(value)
}
let set1 = ChartDataSet(entries: values, label: "Set1")
let data = ChartData(dataSet: set1)
// Some debug output
if data.entryCount > 0 {
let yValue = "\(values[data.entryCount-1].y)"
print("Y : \(yValue)")
for value in values {
print("\(value.y) ", terminator: "")
}
}
self.lineChart.data = data
}
}
最佳答案
尝试使用以下...
let x = [0,1,2,3,4,5,6,7,8,9]
let y = [0,1,2,3,4,5,6,7,8,9]
func setChartValues() {
var values = [ChartDataEntry]()
for index in x {
let value = ChartDataEntry(x: Double(index), y: Double(y[index]))
values.append(value)
}
let set1 = LineChartDataSet(entries: values, label: "Set1")
set1.color = UIColor.blue // red // green whatever you want.
let data = LineChartData()
data.addDataSet(data:set1)
// Some debug output
if data.entryCount > 0 {
let yValue = "\(values[data.entryCount-1].y)"
print("Y : \(yValue)")
for value in values {
print("\(value.y) ", terminator: "")
}
}
self.lineChart.data = data
}
关于swift - iosChart 不在 UITableViewCell 中显示 LineChartView 点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57711264/
我想用 Swift 3 设置条形图,关注 this教程。 我在我的 viewController 中创建了一个 barChartView 并在 viewDidLoad 中创建了数据值: var mon
我在 2 个月后将 ios-charts 更新为最新代码。当我运行代码时,我看到了很多不同之处。 这是在更新库之前: 更新后: 这是生成图表的代码: chart.infoTextColor =
我正在使用 danielgindi/iOSCharts 库来创建组合的折线图和条形图,如下所示。 我的图表呈现正确,并且具有点击和捏合缩放等用户交互。图表还能够检测到我的点击手势。但不知何故 func
我正在尝试开发一个简单的事件图表。我的意图是在图表中选择特定的条形图来显示另一个 View 。主图表旨在成为仪表板样式,因此为了深入发现或详细信息,用户可以选择特定的栏以了解更多信息[应该会显示特定的
以下基于 LineChartView 示例 ( from youtube ),它在标准 View (单 View 应用程序)中运行良好,而 BarChartView 在 TableViewCell 使
使用以下代码 barchart.xAxis.labelTextColor = UIColor.white barchart.xAxis.labelPosition = .topInside barCh
我想在表格单元格中使用水平条形图,因为每个单元格值都将动态分配。谢谢这是 cellForRowAtIndexPath 中的代码强文字 [ self 设置BarLineChartView:cell.ch
我是一名优秀的程序员,十分优秀!