0

好像

图表库 "SwiftCharts" 可以显示 "Default" maxValue 、 midValue 和 minValue ,但是如何隐藏 midValue "98 " ?请帮助我,谢谢!

我在 SwiftCharts 上使用了演示项目: Code func initializeChart(cell: MarketPriceCell, index: 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 }...
4

1 回答 1

0

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]
于 2018-02-09T01:43:05.703 回答