lineChartView轴标签在标签上添加额外的行

问题描述

嗨,我想在每个这样的标签上方添加一行

enter image description here

我尝试过

class XAxisRendererWithTicks: XAxisRenderer {

override func drawLabel(context: CGContext,formattedLabel: String,x: CGFloat,y: CGFloat,attributes: [NSAttributedString.Key: Any],constrainedToSize: CGSize,anchor: CGPoint,angleradians: CGFloat) {

super.drawLabel(context: context,formattedLabel: formattedLabel,x: x,y: y,attributes: attributes,constrainedToSize: constrainedToSize,anchor: anchor,angleradians: angleradians)

context.beginPath()

context.move(to: CGPoint(x: x,y: y))
context.addLine(to: CGPoint(x: x,y: self.viewPortHandler.contentBottom))

context.strokePath()
}}

let customXAxisRenderer = XAxisRendererWithTicks(viewPortHandler: lineChartView.viewPortHandler,xAxis: lineChartView.xAxis,transformer: lineChartView.getTransformer(forAxis: .left))
    lineChartView.xAxisRenderer = customXAxisRenderer
    

这可以使短线,但是如何删除没有标签的短线呢?

enter image description here

谢谢

解决方法

我以此解决了我的问题

override func drawLabel(context: CGContext,formattedLabel: String,x: CGFloat,y: CGFloat,attributes: [NSAttributedString.Key: Any],constrainedToSize: CGSize,anchor: CGPoint,angleRadians: CGFloat) {

    super.drawLabel(context: context,formattedLabel: formattedLabel,x: x,y: y,attributes: attributes,constrainedToSize: constrainedToSize,anchor: anchor,angleRadians: angleRadians)

    if(formattedLabel == ""){
        return
    }
    context.beginPath()

    context.move(to: CGPoint(x: x,y: y))
    context.addLine(to: CGPoint(x: x,y: self.viewPortHandler.contentBottom))

    context.strokePath()
}