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…
- Import the Google Chart API library as follows:
import Graphics.Google.Chart
- 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)
- Print out the Google Chart URL from the pie chart attributes shown in the following code:
putStrLn $ chartURL $ setSize 500 400 $ setTitle "Example of Plotting a Pie Chart in Haskell" $ setData (encodeDataSimple...