-
Notifications
You must be signed in to change notification settings - Fork 85
example 5
geothecoder72 edited this page Jul 26, 2021
·
9 revisions
This chart:
was produced by this code:
import Graphics.Rendering.Chart.Easy
import Graphics.Rendering.Chart.Backend.Cairo
values :: [ (String,Double,Bool) ]
values = [ ("Mexico City",19.2,False), ("Mumbai",12.9,False), ("Sydney",4.3,False), ("London",8.3,False), ("New York",8.2,True) ]
pitem (s,v,o) = pitem_value .~ v
$ pitem_label .~ s
$ pitem_offset .~ (if o then 25 else 0)
$ def
main = toFile def "example5_big.png" $ do
pie_title .= "Relative Populations"
pie_plot . pie_data .= map pitem values
Here is equivalent code without using the Easy helper functions and monadic stateful API:
import Graphics.Rendering.Chart
import Graphics.Rendering.Chart.Backend.Cairo
import Data.Default.Class
import Control.Lens
import System.Environment(getArgs)
chart = toRenderable layout
where
values = [ ("Mexico City",19.2,e), ("Mumbai",12.9,e), ("Sydney",4.3,e), ("London",8.3,e), ("New York",8.2,e1) ]
e = 0
e1 = 25
pitem (s,v,o) = pitem_value .~ v
$ pitem_label .~ s
$ pitem_offset .~ o
$ def
layout = pie_title .~ "Relative Populations"
$ pie_plot . pie_data .~ map pitem values
$ def
main = renderableToFile def "example5_big.png" chart