饼图不可拖动

时间:2017-10-24 15:01:41

标签: swift ios-charts

我正在尝试使用iOS Charts创建一个饼图,我知道饼图的默认设置是让它能够让用户拖动饼图并从中查看它不同的角度。

但是,它似乎无法在这里工作:

func createChildrenPieChart(sections: [String], percents: [Double]) {
    var dataEntries = [ChartDataEntry]()


    for i in 0...(sections.count - 1) {
        let entry = PieChartDataEntry()
        entry.y = percents[i]
        entry.label = sections[i]
        dataEntries.append(entry)


    }

    let chartDataSet = PieChartDataSet(values: dataEntries, label: "")
    let chartData = PieChartData(dataSet: chartDataSet)

    childrenPieChart.data = chartData

    var colors: [UIColor] = []

    for _ in 0..<sections.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)
    }

    chartDataSet.colors = colors
}

任何帮助将不胜感激,我正在使用Xcode 9,Swift 4.0

2 个答案:

答案 0 :(得分:1)

我有一个功能正常的pieChart用户可以旋转,你可以尝试添加它:

    childrenPieChart.rotationEnabled = true
    childrenPieChart.highlightPerTapEnabled = true        
    childrenPieChart.maxAngle = 360.0
    childrenPieChart.isUserInteractionEnabled = true
    childrenPieChart.rotationAngle = 180.0

答案 1 :(得分:1)

您必须设置<p-dialog [(visible)]="display" modal="modal" draggable="true" dismissableMask="true" positionTop="50" padding="0px" width="1200" height="350" [responsive]="true"> <p-header> top header title pass here <button type="button" pButton icon="fa-calculator" (click)="abc()"></button> <button type="button" pButton icon="fa-question" (click)="abc()"></button> </p-header> <p>The stor.</p> <p-footer> <button type="button" pButton icon="fa-check" (click)="display=false" label="Yes">hghk</button> </p-footer> </p-dialog>

isUserInteractionEnabled