Allow PieChartView to hide value line for tiny slices in Swift

前端 未结 1 1459
半阙折子戏
半阙折子戏 2021-01-26 11:03

I\'m building a pie chart by chart iOS framework. I\'m able to hide the value and label when the the slice is tiny but I can\'t hide the value line for tiny slice.

相关标签:
1条回答
  • 2021-01-26 11:27

    Inside the file PieChartRenderer change from this:

     if dataSet.valueLineColor != nil        
     {
        context.setStrokeColor(dataSet.valueLineColor!.cgColor)
        context.setLineWidth(dataSet.valueLineWidth)
    
        context.move(to: CGPoint(x: pt0.x, y: pt0.y))
        context.addLine(to: CGPoint(x: pt1.x, y: pt1.y))
        context.addLine(to: CGPoint(x: pt2.x, y: pt2.y))
    
        context.drawPath(using: CGPathDrawingMode.stroke)
    
     }
    

    to this:

     if dataSet.valueLineColor != nil
     {
    
         if(valueText == "") {
             context.setStrokeColor(UIColor.clear.cgColor)
         }
         else {
             context.setStrokeColor(dataSet.valueLineColor!.cgColor)
         }
    
         context.setLineWidth(dataSet.valueLineWidth)
    
         context.move(to: CGPoint(x: pt0.x, y: pt0.y))
         context.addLine(to: CGPoint(x: pt1.x, y: pt1.y))
         context.addLine(to: CGPoint(x: pt2.x, y: pt2.y))
    
         context.drawPath(using: CGPathDrawingMode.stroke)
     }
    

    The change basically checks if the valueText is the empty string, and if so it changes the linecolor to a clear color.

    0 讨论(0)
提交回复
热议问题