PieChart for ios diagrams broken in Swift 2.0?

So, I updated my project and modules for working with Swift 2.0 and Xcode 7. But now my PieChart no longer works as expected. My pies start from 0 degrees, which means that they all start in the same place one above the other.

Data is added in the same way as before, and if I select it, I see that they are all there, but do not come from their respective places.

Code to add mine pieChartData:

var dataEntries: [ChartDataEntry] = []
var dataPoints: [String] = []

for var i = 0; i < expensesHistory.count; i++ {
    let dataEntry = ChartDataEntry(value: expensesHistory[i].amount, xIndex: i)
    dataEntries.append(dataEntry)
    dataPoints.append(expensesHistory[i].category.rawValue)
}

let pieChartDataSet = PieChartDataSet(yVals: dataEntries)
let pieChartData = PieChartData(xVals: dataPoints, dataSet: pieChartDataSet)
pieChartView.data = pieChartData
var colors = [UIColor]()
colors.append(Colors.blueColor())
pieChartDataSet.colors = colors
pieChartDataSet.drawValuesEnabled = false
pieChartDataSet.sliceSpace = 4.0

The data is loaded and added correctly, in different records (7), but all 7 pies start in the same place ... therefore, they do not lead to a circle at all. Any ideas?

UPDATE # 1

ChartsDemo Swift, , , , , , , DataSet. PieChartDataSet.drawValuesEnabled = true PieChartView.legend.enabled = true, 1 1 DataSet. , xVals yVals 1 , , . , , .

PieChartView, , , , , , , PieChartView 1 , 1 , .

ChartsDemo Swift, , Swift 2.0 ( ).

private func setPieChartData() {

    let mult = UInt32(100)
    let count = Int(4)

    let parties = [
    "Party A", "Party B", "Party C", "Party D", "Party E", "Party F",
    "Party G", "Party H", "Party I", "Party J", "Party K", "Party L",
    "Party M", "Party N", "Party O", "Party P", "Party Q", "Party R",
    "Party S", "Party T", "Party U", "Party V", "Party W", "Party X",
    "Party Y", "Party Z"
    ]

    var yVals1 = [ChartDataEntry]()

    // IMPORTANT: In a PieChart, no values (Entry) should have the same xIndex (even if from different DataSets), since no values can be drawn above each other.
    for var i = 0; i < count; i++
    {
        let chartDataEntry = ChartDataEntry(value: Double((arc4random_uniform(mult) + mult/5)), xIndex: i)
        yVals1.append(chartDataEntry)
    }

    var xVals = [String?]()

    for var i = 0; i < count; i++
    {
        xVals.append(parties[i % parties.count])
        //[xVals addObject:parties[i % parties.count]]
    }

    let dataSet = PieChartDataSet(yVals: yVals1, label: "Election Results")
    dataSet.sliceSpace = 3.0

    // add a lot of colors

    var testColors = [UIColor]()
    testColors.append(Colors.blueColor())
    let data = PieChartData(xVals: xVals, dataSet: dataSet)

    pieChartView.data = data

    dataSet.colors = testColors
    dataSet.drawValuesEnabled = true

    dataSet.sliceSpace = 4.0
}

, iOS-, Swift 2.0, , . , . , , , , PieChartView.

# 2

, , . , .

:

  • Xcode 7.
  • CocoaPods.
  • , CocoaPods, , , "pod install" , .
  • ChartsIssue.xcworkspace , ChartsIssue.xcproj
0
1

, ChartsDemo, , .

, . , - , , ? , , , , , .

:

1. , , :

2. ChartsDemo , ; .

- (void)setDataCount:(int)count range:(double)range
{
    double mult = range;

    NSMutableArray *yVals1 = [[NSMutableArray alloc] init];

    // IMPORTANT: In a PieChart, no values (Entry) should have the same xIndex (even if from different DataSets), since no values can be drawn above each other.
    for (int i = 0; i < count; i++)
    {
        [yVals1 addObject:[[ChartDataEntry alloc] initWithValue:(arc4random_uniform(mult) + mult / 5) xIndex:i]];
    }

    NSMutableArray *xVals = [[NSMutableArray alloc] init];

    for (int i = 0; i < count; i++)
    {
        [xVals addObject:parties[i % parties.count]];
    }

    PieChartDataSet *dataSet = [[PieChartDataSet alloc] initWithYVals:yVals1 label:@"Election Results"];
    dataSet.sliceSpace = 3.0;

    // add a lot of colors

    NSMutableArray *colors = [[NSMutableArray alloc] init];
    [colors addObject:[UIColor blueColor]];

    PieChartData *data = [[PieChartData alloc] initWithXVals:xVals dataSet:dataSet];
    _chartView.data = data;

    dataSet.colors = colors;
    dataSet.drawValuesEnabled = NO;
    dataSet.sliceSpace = 4.0;
}

1 2:

, , , , 4 ;

, , :

pieChartView.animate(xAxisDuration: 1.5, easingOption: ChartEasingOption.EaseOutBack)
pieChartView.animate(yAxisDuration: 1.5, easingOption: ChartEasingOption.EaseOutBack)

, ( , ), .

x y, func, :

pieChartView.animate(xAxisDuration: 1.5, yAxisDuration: 1.5, easingOption: ChartEasingOption.EaseOutBack)

issue, , .

+1

Source: https://habr.com/ru/post/1612076/


All Articles