The original Charts of the project are Swift 2.3 version, we will update the chart library to 3.0 this week, but after the update yesterday, a message said that we want to use Baidu’s Eharts……..

Instead of using Cocoapods, the project drags in the source code directly. So I directly downloaded the Charts from Git and replaced the source code of the chart library into the project.

If that’s you, take note:

Download your project from git:

I’m going to go into the project and I’m going to go into the project and I’m going to go into the project and I’m going to go into the project and I’m going to go into the project and I’m going to go into the project and I’m going to go into the project and I’m going to say NO. Then compile again.

After compiling again, I reported 10 errors here because I didn’t import UIKit framework, so let’s just import UIKit for each file once, and compile successfully. No problem.

Let’s go to the ViewController and import the header chartsstudy-swift.h. This header file is automatically generated by the system for us. The details can be found in Settings:

Let’s start with the simplest bar chart.

#import "ViewController.h"
#import "ChartsStudy-Swift.h"

@interface ViewController(a){
    BarChartView *_barChart;
}
@property (nonatomic.strong) NSArray *barLabel;
@property (nonatomic.strong) NSArray *barData;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Bar graph data
    // The X-axis is the week, Monday to Sunday
    / / amount of Y is
    self.barLabel = @[@" Monday".@" Tuesday".@" Wednesday".@" Thursday".@" Friday".@" Saturday".@" Sunday"];
    self.barData = @[@12.5The @56.7The @0.0The @0.0The @8.8The @4.13The @7.88];
    
    [self nj_BarChartView];
}

- (void)nj_BarChartView
{
    _barChart = [[BarChartView alloc] initWithFrame:CGRectMake(15.15.400.300)];
    [self.view addSubview:_barChart];
    
    [self setBarDataWithCount:self.barData.count];
}

- (void)setBarDataWithCount:(NSInteger)count
{
    
    /* BarChartDataEntry: represents a point that requires x and y values to determine the position of the point. This point is the midpoint at the top of the bar chart. BarChartDataSet: This represents a collection of points above. Represents a set of data. For example, the group here is the performance trend of department A of A company, because A bar chart may contain the performance of several departments, so there may also be many groups of data. BarChartData: This class represents one or more groups of data fused into a single data and presented to a bar graph for display. */
    
    NSMutableArray *yVals = [[NSMutableArray alloc] init];
    
    for (NSInteger i = 0; i < count; ++i) {
        // Instantiate each data point and place it in the yVals array.
        [yVals addObject:[[BarChartDataEntry alloc] initWithX:(double)i y:[self.barData[i] doubleValue]]];
    }
    // Instantiate an array of data points as a data set object
    BarChartDataSet *set = [[BarChartDataSet alloc] initWithValues:yVals label:@"set"];
    // Instantiate one or more data set objects into a data object
    BarChartData *data = [[BarChartData alloc] initWithDataSet:set];
    // Pass the data object to the bar graph for display.
    _barChart.data = data;
    // Add a little animation at the end. Animation is also a lot, you can jump to the head file inside the search.
    [_barChart animateWithXAxisDuration:1.0];
}
@end
Copy the code

After running, the picture is as follows:

This graph is definitely not what you want, but because it has too many attributes, I will simply use this graph to parse it: