gpt4 book ai didi

SwiftCharts 如何隐藏 yLabel 上的 midValue

转载 作者:行者123 更新时间:2023-11-30 11:47:19 27 4
gpt4 key购买 nike

looks like

图表库“SwiftCharts”可以显示“默认” maxValue 、 midValue 和 minValue ,但如何隐藏 midValue “98 ”?请帮助我,谢谢!

我在 SwiftCharts 上使用了演示项目:代码funcinitializeChart(单元格:MarketPriceCell,索引:Int){

//初始化数据系列和标签

var serieData: [Double] = []
var labels: [Double] = []
var labelsAsString: Array<String> = []
let beginInd = 0
let oneFour = stockValuesAll.count / 4
let twoFour = (stockValuesAll.count * 2) / 4
let thrFour = (stockValuesAll.count * 3) / 4
labels = [Double(beginInd), (Double(oneFour)), (Double(twoFour)),(Double(thrFour))]
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyyMMdd"
let ddate1 = dateFormatter.string(from: stockValuesAll[beginInd]["date"] as! Date)
let ddate2 = dateFormatter.string(from: stockValuesAll[oneFour]["date"] as! Date)
let ddate3 = dateFormatter.string(from: stockValuesAll[twoFour]["date"] as! Date)
let ddate4 = dateFormatter.string(from: stockValuesAll[thrFour]["date"] as! Date)

labelsAsString = [ddate1,ddate2,ddate3,ddate4]
/// Date formatter to retrieve the month names
for (_, value) in stockValuesAll.enumerated() {
serieData.append(value["close"] as! Double)

}
let series = ChartSeries(serieData)
series.area = true
// Configure chart layout
cell.stkChart.lineWidth = 0.5
cell.stkChart.labelFont = UIFont.systemFont(ofSize: 12)
cell.stkChart.xLabels = labels
cell.stkChart.xLabelsFormatter = { (labelIndex: Int, labelValue: Double) -> String in
return labelsAsString[labelIndex]
}
cell.stkChart.xLabelsTextAlignment = .left
cell.stkChart.minY = serieData.min()! - 5
cell.stkChart.add(series)

Json 文件:

{
"quotes":
[
{ "date": "2017-07-01", "close": 93.52 },
{ "date": "2017-07-02", "close": 93.48 },
{ "date": "2017-07-03", "close": 94.03 },
{ "date": "2017-07-07", "close": 95.97 }...

最佳答案

y 轴的标签在以下函数中设置:

    fileprivate func drawLabelsAndGridOnYAxis() {
let context = UIGraphicsGetCurrentContext()!
context.setStrokeColor(gridColor.cgColor)
context.setLineWidth(0.5)

var labels: [Double]
if yLabels == nil {
labels = [(min.y + max.y) / 2, max.y]
if yLabelsOnRightSide || min.y != 0 {
labels.insert(min.y, at: 0)
}
} else {
labels = yLabels!
}

因此您必须设置自己的 yLabels 数组(仅包含最小值和最大值)并将它们分配给您的图表。另一种选择是更改上述代码并删除中值的项目:

if yLabels == nil {
labels = [max.y]

关于SwiftCharts 如何隐藏 yLabel 上的 midValue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48679291/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com