Skip to content

Getting started

Alexander Shestacov edited this page Aug 6, 2019 · 4 revisions

Before creating your first iOS application with AnyChart library make sure that Cocoapods is installed on your computer.

Create a new Xcode project.

New Xcode project


Signel View App

Choose "Single View App".

Single View App


Signel View App

Fill product name, organization name, and organization identifier.

Create new project


Create new project

When you click Next, you'll be prompted for a location to save it. Also, you could enable "Create a Git repository".

Close all Xcode projects. Go to the project location in the terminal. Create a POD file in your project by executing the command:

pod init

Open the Podfile in the project folder and type in pod 'AnyChartiOS', '~> 1.0.3' in target section just like it is shown at the screenshot below to include the AnyChartiOS framework version 1.0.3. For using the latest version you can paste the name of the POD without specifying a certain version pod 'AnyChartiOS'.

Install AnyChartiOS POD


Add framework

To install the AnyChartiOS POD execute the following command (the first installation may take some time):

pod install

Now open the .xcworkspace file from the project directory in Xcode.

Open project workspace


Add framework

Go to the "Main.storyboard" and set "AnyChartView" in custom class for your View.

Storyboard


Storyboard

Now click on the "Assistant editor" (two intersected circles at the top) and connect your AnyChartView to the ViewController. To do that, press and hold down the CTRL key while you drag your AnyChartView to the ViewController. Name it as "anyChartView".

Assistant editor


Assistant editor

Go to the ViewController and make sure you have import "AnyChartiOS" at the top of your ViewController.

Import AnyChartiOS


Assistant editor

Add code in the "viewDidLoad" method. For example, if you want to create a simple pie chart:

let chart = AnyChart.pie()

let data: Array<DataEntry> = [
    ValueDataEntry(x: "Apples", value: 6371664),
    ValueDataEntry(x: "Pears", value: 789622),
    ValueDataEntry(x: "Bananas", value: 7216301),
    ValueDataEntry(x: "Grapes", value: 1486621),
    ValueDataEntry(x: "Oranges", value: 1200000)
]
chart.data(data: data)

chart.title(settings: "Fruits imported in 2015 (in kg)")

anyChartView.setChart(chart: chart)

Pie Chart


Pie Chart

Run your project.

Running project


Running project