Working With CorePlot: Project Setup

When working with data intensive applications, a developer must often do more than just show lists of data records in a table view. The CorePlot library will allow you to add stunning data visualizations to your applications. Find out how in this Tuts+ Premium series!

Data visualisation is critical in helping the user make sense of data and to make important decisions. CorePlot is a third party library that allows you to display a range of interactive graphs within your application. This includes line graphs, scatterplot graphs, bar graphs, and even pie charts. You can customize the look of the graphs and even allow the user to interact with them.


Also available in this series:

  1. Working With CorePlot: Project Setup
  2. Working with CorePlot: Plot Fundamentals
  3. Working with CorePlot: Styling and Adding Plots
  4. Working with CorePlot: Creating a Bar Chart
  5. Working with CorePlot: Creating a Pie Chart

What We Will Cover

Over the next 5 tutorials we will be creating an application that graphs data about student enrollment in a university. Specifically, we will cover:

  • How to add CorePlot to an application.
  • The basics of CorePlot and how to get a graph working.
  • Creating a line graph.
  • Styling graphs.
  • Creating a bar chart.
  • Abstracting graph data logic.
  • Creating a pie chart.

Required Knowledge

You must have an intermediate understanding of iOS development and the delegation pattern of development. An understanding of CoreData is helpful but not required. Much of the CoreData functionality has already been implemented and you will be guided through any further calls to the data store.


The Sample Application

In the source code you will find the base application we will use going forward. It is a basic tab bar application that uses Core Data to store student and subject information and lists them in separate table views. You can add a student or subject by pressing the "+" button in the top right hand corner.

The subject class has the following attributes:

  • Subject ID: Unique identifier, automatically generated.
  • Subject Name: Subject name, describes what the subject is about.

The student class has the following attributes:

  • Student ID:Unique identifier, automatically generated.
  • Student Name: The given and surname of the student.
  • Subject ID: The subject ID that they are enrolled in. For simplicities sake we assume that a student can only enroll in one subject.
  • Day Enrolled: We assume the enrollment goes over a 7 day period. The day enrolled is the day that the student has come in during that period to enroll.

Open the project and make sure that it runs. For this series I am not using Automatic Reference Counting, so we will have to manage our own memory. You should see the application launch with a "Students" and "Subjects" tab. Each tab should contain a tableView with some pre-populated data in each. Once you've confirmed this is all working, we can move on to adding CorePlot into our application.



Importing CorePlot

The first step is to download the latest version of CorePlot. At the time of writing that is v1.0. Visit the core plot home page and navigate to the downloads section.


Download the zip file. The library is around 140 mb so it may take awhile if you have a slow connection.

We're going to put the CorePlot Library files within our application. It is good practice to store third parties in a folder separate from the other class files. Create a new folder in the "StudentTracker" source folder called "External Libraries".

You can include CorePlot as a dependent project install or a static library. I like including it as a dependent project install as it allows us to access the source code and see how things work as distinct form just seeing the header files.

  1. Copy the "CorePlot" directory into the newly created "External Libraries" folder inside the StudentTracker source folder.

  2. Create a group in XCode called the same ("External Libraries")

  3. In finder, locate the "CocoaTouch.xcodeproj" project file ("CorePlot_1.0/Source/frameworkCocoaTouch.xcodeproj") and drag it into the "External Libraries" group in Xcode.

  4. Select your application project file in xcode and click on the "Build Phases" tab. From there you need to add the CorePlot-CocoaTouch Library in the "Target Dependencies" group.
  5. You'll also need to link the binary with the CorePlot library. Expand the "Link Binary with Libraries" group and add the "libCorePlot-CocoaTouch.a"

  6. You'll also need to add some settings in the Build Settings tab. Set the header search path to the framework directory in the CorePlot source directory (should be "${PROJECT_DIR}/StudentTracker/External libraries/CorePlot_1.0/Source/framework/"). Tick the box to the right of the text (to indiciate recursive). You should also change "Always Search User Paths" to "Yes".

  7. Next, add "-ObjC" to the "Other Linker Flags" field.
  8. CorePlot relies on the QuartzCore framework, so go ahead and add that as a required framework.
  9. Finally, you will need to import the "CorePlot-cocoaTouch.h" file into any files that require it. We don't need it yet, but just try adding it to the application delegate file to ensure everything compiles correctly.

If the project compiles successfully then everything is good to go!


Common Problems

This means that the header path search folder hasn't been located correctly. Make sure that you are using the "Header Search Paths" and not "Framework Search Paths". It is important to make sure the checkbox is ticked and "Always Search User Paths" is set to "Yes".

These scary looking errors exist because the QuartzCore Framework hasn't been included. All you need to do is include the QuartzCore Framework (in the "Link Binary With Libraries" group) and these errors will go away!


Wrap up

We've gotten a good introduction to what CorePlot can do and how to add it to an existing project. Next time we're going to get our hands dirty and start building a line graph to show how many students enrolled on each enrollment day. Catch you next time!

Tags:

Comments

Related Articles