-
Notifications
You must be signed in to change notification settings - Fork 85
example 3
Tim Docker edited this page Jan 29, 2015
·
8 revisions
This chart:
was produced by this code:
import Graphics.Rendering.Chart.Easy
import Graphics.Rendering.Chart.Backend.Cairo
import Data.Time.LocalTime
import Prices(prices1)
fillBetween title vs = liftEC $ do
plot_fillbetween_title .= title
color <- takeColor
plot_fillbetween_style .= solidFillStyle color
plot_fillbetween_values .= vs
main = toFile def "example3_big.png" $ do
layout_title .= "Price History"
plot (fillBetween "price 1" [ (d,(0,v2)) | (d,v1,v2) <- prices1])
plot (fillBetween "price 2" [ (d,(0,v1)) | (d,v1,v2) <- prices1])
Here is equivalent code without using the Easy helper functions and monadic stateful API:
import System.Environment(getArgs)
import Data.Time.LocalTime
import Graphics.Rendering.Chart
import Graphics.Rendering.Chart.Backend.Cairo
import Data.Colour
import Data.Colour.Names
import Data.Colour.SRGB
import Data.Default.Class
import Control.Lens
import Prices(prices1)
green1 = opaque $ sRGB 0.5 1 0.5
blue1 = opaque $ sRGB 0.5 0.5 1
chart = toRenderable layout
where
price1 = plot_fillbetween_style .~ solidFillStyle green1
$ plot_fillbetween_values .~ [ (d,(0,v2)) | (d,v1,v2) <- prices1]
$ plot_fillbetween_title .~ "price 1"
$ def
price2 = plot_fillbetween_style .~ solidFillStyle blue1
$ plot_fillbetween_values .~ [ (d,(0,v1)) | (d,v1,v2) <- prices1]
$ plot_fillbetween_title .~ "price 2"
$ def
layout = layout_title .~ "Price History"
$ layout_grid_last .~ True
$ layout_plots .~ [toPlot price1, toPlot price2]
$ def
main = renderableToFile def "example4_big.png" chart