2017-08-21 86 views
0

現在我用一個餅圖從Charts迅速設置圖像中心餅圖

我想將圖像添加到圖表的中心,而不是餅圖。

image

我應該怎麼辦?

代碼

func updatePieChart(){ 
    let track = ["", ""] 
    let money = [65, 45] 
    var entries = [PieChartDataEntry]() 
    for (index, value) in money.enumerated() { 
     let entry = PieChartDataEntry() 
     entry.y = Double(value) 
     entry.label = track[index] 
     entries.append(entry) 
    } 
    let set = PieChartDataSet(values: entries, label: "Pie Chart") 
    var colors: [UIColor] = [] 

    for _ in 0..<money.count { 
     let red = Double(arc4random_uniform(256)) 
     let green = Double(arc4random_uniform(256)) 
     let blue = Double(arc4random_uniform(256)) 
     let color = UIColor(red: CGFloat(red/255), green: CGFloat(green/255), blue: CGFloat(blue/255), alpha: 1) 
     colors.append(color) 
    } 
    set.colors = colors 
    let data = PieChartData(dataSet: set) 
    pieview.data = data 
    pieview.noDataText = "No data available" 
    // user interaction 
    pieview.isUserInteractionEnabled = true 

    let d = Description() 
    d.text = "iOSCharts.io" 
    pieview.chartDescription = d 
    pieview.centerText = "Pie Chart" 
    pieview.holeRadiusPercent = 0.9 
    pieview.transparentCircleColor = UIColor.clear 
    pieview.holeRadiusPercent = 0.65 
    pieview.transparentCircleRadiusPercent = 0 
    pieview.legend.enabled = false 
    pieview.chartDescription?.enabled = false 

回答

0

請試試這個:

let attachment = NSTextAttachment() 
attachment.image = UIImage(named: "your image") 
let attachmentString = NSAttributedString(attachment: attachment) 
let labelImg = NSMutableAttributedString(string: "") 
labelImg.append(attachmentString) 

pieChartView.centerAttributedText = labelImg 
+0

這方面的工作? –

0

試試這個,而不是

@IBOutlet weak var chartView: PieChartView! 
@IBOutlet weak var image: UIImageView! 
... 

image.center = chartView.center