Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何使用“danielgindi/Charts”使值与PieChartView上的中心对齐`_Ios_Swift_Charts_Pie Chart_Ios Charts - Fatal编程技术网

Ios 如何使用“danielgindi/Charts”使值与PieChartView上的中心对齐`

Ios 如何使用“danielgindi/Charts”使值与PieChartView上的中心对齐`,ios,swift,charts,pie-chart,ios-charts,Ios,Swift,Charts,Pie Chart,Ios Charts,我在iOS应用程序中使用,并在PieChartView中显示数据,如下图所示 这里的问题是,如果分别检查早晚饼图中的值5、5、10和5、6、9,则没有中心对齐。我试过他们提供的很多房产,但我没有弄明白。你能帮我修一下吗 我也附上代码 @IBOutlet weak var morningPieChartView: PieChartView! @IBOutlet weak var eveningPieChartView: PieChartView! self.setupPieChartView

我在iOS应用程序中使用,并在
PieChartView
中显示数据,如下图所示

这里的问题是,如果分别检查早晚饼图中的值5、5、10和5、6、9,则没有中心对齐。我试过他们提供的很多房产,但我没有弄明白。你能帮我修一下吗

我也附上代码

@IBOutlet weak var morningPieChartView: PieChartView!
@IBOutlet weak var eveningPieChartView: PieChartView!


self.setupPieChartView(self.morningPieChartView, data: [10, 5, 5])
self.setupPieChartView(self.eveningPieChartView, data: [9, 6, 5])


 private func setupPieChartView(_ pieChart: PieChartView, data: [Double]) {
    
    pieChart.clear()
    pieChart.clearValues()
    pieChart.clearAllViewportJobs()
    pieChart.clearsContextBeforeDrawing = true
            
    var dataEntries = [PieChartDataEntry]()
    
    for (_, value) in data.enumerated() {
        let entry = PieChartDataEntry()
        entry.y = value
        dataEntries.append(entry)
    }
    
    let pieChartDataSet = PieChartDataSet(entries: dataEntries)
    pieChartDataSet.drawValuesEnabled = true
    pieChartDataSet.valueTextColor = UIColor.white
    pieChartDataSet.valueFont = UIFont.PathwayGothicOneRegular(10)

    let data = PieChartData(dataSet: pieChartDataSet)
    data.setValueTextColor(.white)
    data.setValueFont(UIFont.PathwayGothicOneRegular(10))
    
    let pFormatter = NumberFormatter()
    pFormatter.maximumFractionDigits = 0
    data.setValueFormatter(DefaultValueFormatter(formatter: pFormatter))

    pieChart.data = data
    
    pieChart.usePercentValuesEnabled = false
    pieChart.highlightPerTapEnabled = false
    pieChart.drawHoleEnabled = false
    pieChart.legend.enabled = false
    pieChart.noDataTextColor = UIColor.white
    pieChart.noDataFont = UIFont.PathwayGothicOneRegular(13.3)
    pieChart.setNeedsDisplay()
    
    let color1 = UIColor(named: "204_170_140") ?? .clear
    let color2 = UIColor(named: "189_157_129") ?? .clear
    let color3 = UIColor(named: "154_128_109") ?? .clear
    let color4 = UIColor(named: "137_114_98") ?? .clear

    let colors: [UIColor] = [color1, color2, color3, color4]

    if colors.count <= dataEntries.count {
        pieChartDataSet.colors = Array(colors[0..<dataEntries.count])
    } else {
        pieChartDataSet.colors = colors
    }
    
} 
@ibvar-morningPieChartView:PieChartView!
@IBV弱var EvenningPieChartView:PieChartView!
self.setupPieChartView(self.morningPieChartView,数据:[10,5,5])
self.setupPieChartView(self.eveningPieChartView,数据:[9,6,5])
专用函数设置PieChartView(pieChart:PieChartView,数据:[双]){
pieChart.clear()
pieChart.clearValues()
pieChart.clearAllViewportJobs()
pieChart.ClearContextBeforeDrawing=true
var dataEntries=[PieChartDataEntries]()
对于data.enumerated()中的(x,value){
let entry=PieChartDataEntry()
entry.y=值
dataEntries.append(条目)
}
让pieChartDataSet=pieChartDataSet(条目:dataEntries)
pieChartDataSet.drawValuesEnabled=true
pieChartDataSet.valueTextColor=UIColor.white
pieChartDataSet.valueFont=UIFont.PathwayGothiconregular(10)
let data=PieChartData(数据集:pieChartDataSet)
data.setValueTextColor(.white)
data.setValueFont(UIFont.pathwaygothiconregular(10))
设pFormatter=NumberFormatter()
pFormatter.maximumFractionDigits=0
data.setValueFormatter(DefaultValueFormatter(格式化程序:pFormatter))
pieChart.data=数据
pieChart.usePercentValuesEnabled=false
pieChart.highlight=false
pieChart.drawHoleEnabled=false
pieChart.legend.enabled=false
pieChart.noDataTextColor=UIColor.white
pieChart.noDataFont=UIFont.pathwaygothiconregular(13.3)
pieChart.setNeedsDisplay()
设color1=UIColor(命名为:“204_170_140”)??清除
设color2=UIColor(命名为:“189_157_129”)??清除
设color3=UIColor(命名为:“154_128_109”)??清除
设color4=UIColor(命名为:“137_114_98”)??清除
让颜色:[UIColor]=[color1、color2、color3、color4]
如果是颜色,请计数