Charts with a frame for a chart, you can draw a bar chart, line chart, chart, pie chart. Because Charts only Swift version, so here the detailed explain in the OC project how to import the Charts framework, the following began to do step by step!
First, download the Charts framework
Download address: https://github.com/danielgindi/Charts.
unzip the contents of the folder inside this is the case, as follows:
after extracting the contents of the folder inside
After downloading, it is important to take a closer look at the environment! Following figure:
required configuration environment
Two, the new project, import Charts.xcodeproj project
1 new projects
New project, named ImportChartsDemo.
2 copy the entire Charts file to the ImportChartsDemo project
Where is Charts? Here, the following figure:
Charts file location
Then copy the Charts file to the ImportChartsDemo project, as shown below;
copy Charts entire file to ImportChartsDemo project
3 import Charts.xcodeproj project
The Charts folder in the Charts.xcodeproj project file into the ImportChartsDemo project, note that the introduction of the Charts.xcodeproj project, rather than the Charts folder, as follows:
import Charts.xcodeproj project
4 add Charts.framework
Find General-> Embedded Binaries, click + number to add Charts.framework, as shown below:
Embedded Binaries position
Add iOS to the framework, as shown below:
Three, the establishment of OC and Swift bridge file
In the ImportChartsDemo project to create a new Swift file, the name casually take, this time will prompt whether to establish a bridge file, the direct election of the Create Bridging Header options, as shown below:
to create a bridging file
is completed, it will automatically generate a bridging file, as shown below:
automatically generated bridging file
Four, set compiler options and the introduction of Charts
1 set compiler options
Find Build Settings -> Embedded Contains Swift Code option, set to Yes, as shown in figure:
set compiler options
2 introduction of Charts in a bridging file
3 in the ViewController.m to introduce the relevant header files
After the completion of the introduction, compile it, if there is a mistake, Clean once again compile, compile error free instructions have been successful
In the ViewController.m test, the code is as follows:
BarChartView *chatView = [[BarChartView initWithFrame:CGRectMake (10, 100, 300, 300)] [self.view addSubview:chatView] (alloc]);
Operating results are as follows:
Because there is no data, so the show is No chart aviailable.
so far, the integration of Charts is completed!
Demo address: https://coding.net/u/wanglei123/p/ImportChartsDemo/git.