Plotting a pie chart using Google's Chart API

The Google Chart API provides a very elegant-looking pie chart interface. We can generate images of well-designed pie charts by feeding our input and labels properly, as described in this recipe.

Getting ready

Install the GoogleChart package as follows:

$ cabal install hs-gchart

Create a file called input.txt with numbers inserted line by line as follows:

$ cat input.txt 
2
5
3
7
4
1
19
18
17
14
15
16

How to do it…

  1. Import the Google Chart API library as follows:
    import Graphics.Google.Chart
  2. Gather the input from the text file and parse it as a list of integers, as shown in the following code snippet:
    main = do
      rawInput <- readFile "input.txt"
      let nums = map (read :: String -> Int) (lines rawInput)
  3. Print out ...

Get Haskell Data Analysis Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.