gpt4 book ai didi

ios - 如何设置iOS雷达图的坐标轴选项?

转载 作者:行者123 更新时间:2023-11-28 06:29:06 25 4
gpt4 key购买 nike

我想用 danielgindi 的 iOS 图表库绘制雷达图,但我不知道如何使用选项,尤其是关于轴的选项。

它通常可以正常工作,但是当我将变量列表 (array) 设置为 [100.0, 100.0, 100.0, 100.0, 100.0] 时,它显示得太大了像这样的图表:

相反,当我将 array 设置为 [90.0, 80.0, 90.0, 70.0, 20.0] 时,尽管我的代码,网格线的间隔不是 20 :

从这些输出来看,问题的原因似乎是轴的选项。但是,我无法自己解决这个问题。
如何固定图表的大小和坐标轴的范围,并随心所欲地绘制网格线?

我使用 Xcode 8.1/swift 2.3/Charts 2.3.1。

import UIKit
import Charts

class ViewController: UIViewController {

@IBOutlet weak var radarChartView: RadarChartView!

//Label
let subjects = ["English", "Math", "Physics", "Chemistry", "Biology"]
//Points
let array = [100.0, 100.0, 100.0, 100.0, 100.0]

override func viewDidLoad() {
super.viewDidLoad()
setChart(subjects, values: array)
print("array:")
print(array)
}

func setChart(dataPoints: [String], values: [Double]) {

radarChartView.noDataText = "You need to provide data for the chart."
var dataEntries: [ChartDataEntry] = []
for i in 0..<dataPoints.count {
let dataEntry = ChartDataEntry(value: values[i], xIndex: i)
dataEntries.append(dataEntry)
}
let chartDataSet = RadarChartDataSet(yVals: dataEntries, label: "Units Sold")
let chartData = RadarChartData(xVals: subjects, dataSet: chartDataSet)
radarChartView.data = chartData

//Options of radarChart
radarChartView.sizeToFit()
radarChartView.descriptionText = ""

//Options for the axis from here. The range is 0-100, the interval is 20
radarChartView.yAxis.labelCount = 6
radarChartView.yAxis.axisMinValue = 0.0
radarChartView.yAxis.axisMaxValue = 100.0

radarChartView.rotationEnabled = false
chartDataSet.drawFilledEnabled = true

//Present the number as integer
let numberFormatter = NSNumberFormatter()
numberFormatter.generatesDecimalNumbers = false
chartDataSet.valueFormatter = numberFormatter
radarChartView.yAxis.valueFormatter = numberFormatter

//Other options
radarChartView.legend.enabled = false
radarChartView.yAxis.gridAntialiasEnabled = true
radarChartView.animate(yAxisDuration: 2.0)
}

最佳答案

我只需要在选项之后设置数据。 picture

func setChart(dataPoints: [String], values: [Double]) {
radarChartView.noDataText = "You need to provide data for the chart."
var dataEntries: [ChartDataEntry] = []
for i in 0..<dataPoints.count {
let dataEntry = ChartDataEntry(value: values[i], xIndex: i)
dataEntries.append(dataEntry)
}
let chartDataSet = RadarChartDataSet(yVals: dataEntries, label: "Units Sold")

//Set options...

//Then set data
let chartData = RadarChartData(xVals: subjects, dataSet: chartDataSet)
}

关于ios - 如何设置iOS雷达图的坐标轴选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40906483/

25 4 0
文章推荐: javascript - SystemJS、Typescript、Angular2 和模块化
文章推荐: javascript - 在 HTML 和 JS 中制作响应式复选框?
文章推荐: javascript - 如何使 "Select"文本在下拉菜单中不可见(由