【问题标题】:lineChartView axis label add extra line on the labellineChartView 轴标签在标签上添加额外的线
【发布时间】:2020-08-14 02:15:30
【问题描述】:

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

我试过了

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
    

这样可以做短线,但是没有标签的短线怎么去掉呢?

谢谢

【问题讨论】:

    标签: ios swift charts swift4


    【解决方案1】:

    我通过这个解决了我的问题

    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()
    }
    

    【讨论】:

      猜你喜欢
      • 2022-08-13
      • 1970-01-01
      • 2016-12-19
      • 1970-01-01
      • 2017-11-05
      • 1970-01-01
      • 1970-01-01
      • 2011-06-15
      • 1970-01-01
      相关资源
      最近更新 更多