如何在 ios-图表中创建标记
How to create marker in ios-chart
我正在寻找折线图的标记实现。我正在使用 swift 3. 我所有的搜索都失败了,我需要帮助。
我完成了 个步骤,但似乎效果不佳。
我有两个图表,当我触摸它们时 - 没有任何动作(示例如下)。
@IBOutlet weak var modelLineChartView: LineChartView!
@IBOutlet weak var lineChartView: LineChartView!
.....
func chartValueSelected(chartView: ChartViewBase, entry: ChartDataEntry, highlight: Highlight) {
let graphPoint = modelLineChartView.getMarkerPosition(highlight: highlight)
let graphPointt = lineChartView.getMarkerPosition(highlight: highlight)
print(graphPoint.x)
print(graphPointt.x)
}
请帮助我,我卡住了。
另一个线程中的代码不起作用的原因是 swift 3.0 中的 chartValueSelected 函数与旧版本中的函数略有不同。我创建了一个测试项目,每次单击一个值时都会使用此代码打印出来:
import Charts
class ViewController: UIViewController, ChartViewDelegate {
@IBOutlet weak var testLineChartView: LineChartView!
override func viewDidLoad() {
super.viewDidLoad()
testLineChartView.delegate = self
let data = generateLineData()
testLineChartView.data = data
}
func chartValueSelected(_ chartView: ChartViewBase, entry: ChartDataEntry, highlight: Highlight) {
print("entry.value \(entry)")
}
func generateLineData() -> LineChartData {
let data: LineChartData = LineChartData()
var entries: [ChartDataEntry] = []
var dataArr: [Int] = []
dataArr.append(10)
dataArr.append(5)
dataArr.append(8)
dataArr.append(12)
dataArr.append(10)
for index in 0..<5 {
entries.append(ChartDataEntry(x: Double(index)+0.5, y: Double(dataArr[index]) ) )
}
let set: LineChartDataSet = LineChartDataSet(values: entries, label: "Label")
set.setCircleColor(UIColor.blue)
set.lineWidth = 1
set.circleRadius = 5
set.drawCircleHoleEnabled = false
set.valueTextColor = UIColor.blue
set.valueFont = UIFont(name: "Verdana", size: 12.0)!
set.drawFilledEnabled = true
set.mode = Charts.LineChartDataSet.Mode.linear
set.axisDependency = Charts.YAxis.AxisDependency.left
data.addDataSet(set)
return data
}
}
我正在寻找折线图的标记实现。我正在使用 swift 3. 我所有的搜索都失败了,我需要帮助。
我完成了
我有两个图表,当我触摸它们时 - 没有任何动作(示例如下)。
@IBOutlet weak var modelLineChartView: LineChartView!
@IBOutlet weak var lineChartView: LineChartView!
.....
func chartValueSelected(chartView: ChartViewBase, entry: ChartDataEntry, highlight: Highlight) {
let graphPoint = modelLineChartView.getMarkerPosition(highlight: highlight)
let graphPointt = lineChartView.getMarkerPosition(highlight: highlight)
print(graphPoint.x)
print(graphPointt.x)
}
请帮助我,我卡住了。
另一个线程中的代码不起作用的原因是 swift 3.0 中的 chartValueSelected 函数与旧版本中的函数略有不同。我创建了一个测试项目,每次单击一个值时都会使用此代码打印出来:
import Charts
class ViewController: UIViewController, ChartViewDelegate {
@IBOutlet weak var testLineChartView: LineChartView!
override func viewDidLoad() {
super.viewDidLoad()
testLineChartView.delegate = self
let data = generateLineData()
testLineChartView.data = data
}
func chartValueSelected(_ chartView: ChartViewBase, entry: ChartDataEntry, highlight: Highlight) {
print("entry.value \(entry)")
}
func generateLineData() -> LineChartData {
let data: LineChartData = LineChartData()
var entries: [ChartDataEntry] = []
var dataArr: [Int] = []
dataArr.append(10)
dataArr.append(5)
dataArr.append(8)
dataArr.append(12)
dataArr.append(10)
for index in 0..<5 {
entries.append(ChartDataEntry(x: Double(index)+0.5, y: Double(dataArr[index]) ) )
}
let set: LineChartDataSet = LineChartDataSet(values: entries, label: "Label")
set.setCircleColor(UIColor.blue)
set.lineWidth = 1
set.circleRadius = 5
set.drawCircleHoleEnabled = false
set.valueTextColor = UIColor.blue
set.valueFont = UIFont(name: "Verdana", size: 12.0)!
set.drawFilledEnabled = true
set.mode = Charts.LineChartDataSet.Mode.linear
set.axisDependency = Charts.YAxis.AxisDependency.left
data.addDataSet(set)
return data
}
}