-
Notifications
You must be signed in to change notification settings - Fork 85
Getting started
Here's some minimal instructions to get the Chart library up and running.
Follow the installation instructions for the Haskell Tool Stack tool (stack).
In an empty directory, create a minimal stack.yaml
file:
resolver: lts-7.5
packages: []
extra-deps: []
and run
stack setup
stack build Chart-diagrams
Then create a script to draw a chart called mychart.hs
:
import Graphics.Rendering.Chart.Easy
import Graphics.Rendering.Chart.Backend.Diagrams(toFile)
signal :: [Double] -> [(Double,Double)]
signal xs = [ (x,(sin (x*3.14159/45) + 1) / 2 * (sin (x*3.14159/5))) | x <- xs ]
main = toFile def "mychart.svg" $ do
layout_title .= "Amplitude Modulation"
setColors [opaque blue, opaque red]
plot (line "am" [signal [0,(0.5)..400]])
plot (points "am points" (signal [0,7..400]))
and generate the output file with
stack runghc mychart.hs
Note that this example uses the diagrams backend. This backend is slower than the cairo one, but doesn't depend on gtk2hs (which needs extra installation steps).
Getting started on Windows 10 with the Cairo backend may need some additional steps.
-
Install the MSYS2 software distro and building platform for Windows, following the instructions here. The following assumes that MSYS2 has been installed to the default location (namely,
C:\msys64
). -
Certain Windows environmental variables need to be set up.
First, the locations of the MSYS2 tools need to be added to the PATH
. For example:
SET PATH=C:\msys64\mingw64\bin;C:\msys64\usr\bin;%PATH%
Also, two other environmental variables need to be set:
SET PKG_CONFIG_PATH=C:\msys64\mingw64\lib\pkgconfig
SET XDG_DATA_DIRS=C:\msys64\mingw64\share
- In the MSYS2 environment, use
pacman
to install the following packages:mingw64/mingw-w64-x86_64-pkg-config
,mingw64/mingw-w64-x86_64-gobject-introspection
,mingw64/mingw-w64-x86_64-gtksourceview3
. For example:
pacman -S -q --noconfirm mingw64/mingw-w64-x86_64-pkg-config mingw64/mingw-w64-x86_64-gobject-introspection mingw64/mingw-w64-x86_64-gtksourceview3
- Back in the Windows environment, replace any older versions of
zlib1.dll
on the path with the version provided by MSYS2.
The DLL build of zlib is named zlib1.dll
. zlib has developed over time and later versions of zlib1.dll
export functions that are not available in earlier versions.
In particular, at the time of writing, the version of GHC installed by stack (GHC version 8.6.5) includes version 1.2.8 of zlib released in April 2003. The version provided by MSYS2 is 1.2.11 released in January 2017.
Unfortunately, the stack environment prefixes its out of date version of zlib1.dll
to the PATH
environment variable.
Other applications may also put superseded versions of zlib1.dll
on the PATH
ahead of the version provided by MSYS2. This can give rise to obscure errors when building Haskell projects that depend on GTK+ or its dependencies.
You can find the location of versions on zlib1.dll
on the PATH
in the stack environment with:
stack exec where -- zlib1.dll
The solution is to replace each out-of-date zlib1.dll
with the more up-to-date version provided by MSYS2. It is a good idea first to make a backup of the file being replaced (for example, by renaming it with .old
added to the file name), in case the replacement has an adverse effect.