[Swift] Set Up a Basic Bar Chart Using iOS-Charts

iOS-Charts is a very flexible, easy-to-use third-party library, allowing you to highly customise your chart.

Penny Ng
CodeX
Published in
5 min readMar 22, 2021

--

I recently use iOS-Charts at work. It’s a very flexible, easy-to-use third-party library, allowing you to highly customise your chart.

This library is around 95% similar to its Android counterpart, making developing apps for both platforms much easier.

Here I use some high-income countries' birth rate data to demonstrate how to set up a basic bar chart using iOS-Charts.

Before Starting

The source code is shown below. In case you are a bit confused about some classes or functions I use in this example, here is a little explanation about raw data processing that is not relevant to today’s topic iOS-Charts:

The raw data in this example is a string array.

CountryItem is a class created to store the index, the country and the birth rate of each country. Function getFormattedItemValue parses the raw data and return a CountryItem array.

In viewDidLoad(), getFormattedItemValue is called to process the raw data and the returned data is stored in items.

Setting Up a Chart View

Firstly, add a UIView to the storyboard and set its class to BarChartView.

Don’t forget to import Charts to the code file of this view controller.

The view controller must conform to ChartViewDelegate and set the delegate of the chart view to self.

Now if you run the simulator, it should show “No chart data available.” If your chart view does not show these words, you…

--

--

Penny Ng
CodeX
Writer for

A passionate self-taught  iOS developer. Write to record my learning and share the knowledge. Twitter @pennyngpw