Building your own chart in iOS — Part 1: Bar chart (Revised)

Minh Nguyen
7 min readAug 24, 2017

In this article, I will share with you the way I build my own bar chart without using any third-party library.

I use Swift 5.0 and XCode 10.1 for the sample project and the source code is provided at the end of this post.

Of course, there are a number of good chart libraries for iOS out there. You may consider using one of them before building one for your own if they match your need. However, do it yourself is relatively straightforward and will definitely helps you learn more. It also has some other advantages:

  • Flexible design: You can make it look like whatever you want it to be. A third-party library may not have a chart that look like the design that your company provided you.
  • No code redundancy: Because you just build what you need.

Objective

I will walk you through how to build the bar chart below, of course, with the animation. Since I received quite a number of emails asking me how to animate the bar chart, so, I decided to make it animatable.

Chart 1: Beautiful bar chart

In this article, I will only discuss about the key ideas and not too much about the source code since you can easily download and view it.

What you need to know

--

--