MyNixOS website logo
Description

Haskell wrapper for the Google Chart API.

This module is a wrapper around the Google Chart API. It exposes a rich set of Haskell data types to specify your chart data, which can then be converted into a URL that generates the PNG image of the chart. This package is very old and not really supported.

Hackage version Linux build status

Introduction

GChart is a Haskell wrapper around Google Chart API.

There is a library on Hackage called GoogleChart which provides another wrapper, however it has not been updated in a long while. GChart improves upon that effort by trying to design a more elegant API, and supporting more chart types and features.

Installation

cabal install hs-gchart

Documentation

Getting Started

These examples below are available in examples/Examples.hs in the source tarball. Look at the source file for more Some examples are taken from this article

For examples 1 and 2, the following code is common

dataSeries1 :: [Int]
dataSeries1 = [10,20,8,25,5,3,15,9,5]

labelSeries1 = ["Egg nog",
                "Christmas Ham",
                "Milk (not including egg nog)",
                "Cookies",
                "Roasted Chestnuts",
                "Chocolate",
                "Various Other Beverages",
                "Various Other Foods",
                "Snacks"]

Example 1 : Pie Chart

The code below

 christmasPie = getChartUrl $ do setChartSize 600 300
                                 setDataEncoding simple
                                 setChartType Pie
                                 addChartData dataSeries1
                                 setChartTitle "Food and Drink Consumed Christmas 2007"
                                 setLabels labelSeries1
                                 setColors ["00AF33",
                                            "4BB74C",
                                            "EE2C2C",
                                            "CC3232",
                                            "33FF33",
                                            "66FF66",
                                            "9AFF9A",
                                            "C1FFC1",
                                            "CCFFCC" ]

Generates the following chart.

Generated Pie Chart

Example 2 : Bar Chart

The code below

barGraph = getChartUrl $ do setChartSize 600 300
                            setDataEncoding simple
                            setChartType BarHorizontalGrouped
                            addChartData dataSeries1
                            setChartTitle "Food and Drink Consumed Christmas 2007"
                            addAxis $ makeAxis {  axisType = AxisBottom }
                            addAxis $ makeAxis {  axisType = AxisLeft,
                                                  axisLabels = Just labelSeries1 }
                            addColor "00AF33"

Generates the following chart

Generated Bar Chart

Example 3 : Line XY Chart 1

The code below

linexyGraph1 =
    getChartUrl $ do setChartSize 800 300
                     setChartType LineXY
                     setDataEncoding text
                     setChartTitle "Projected Christmas Cheer for 2007"
                     setGrid $ makeGrid { xAxisStep = 3.333,
                                          yAxisStep = 10,
                                          lineSegmentLength = Just 1,
                                          blankSegmentLength = Just 3 }
                     addAxis $ makeAxis { axisType = AxisLeft,
                                          axisRange = Just $ Range (0,100) (Just 50) }
                     addAxis $ makeAxis { axisType = AxisBottom,
                                          axisLabels = Just $ ["Dec 1st"] ++ blanks 4 ++ ["6th"] ++ blanks 18 ++ ["25th","26th"] ++ blanks 4 ++ ["Dec 31st"] }
                     addChartDataXY dataSeries2

dataSeries2 :: [(Float,Float)]
dataSeries2 = [(0,0),(100,100)]

blanks x = take x $ repeat ""

Generates the following chart

Line Graph

Example 4 : Line XY Chart 2

The code below

linexyGraph2 =
    getChartUrl $ do setChartSize 800 300
                     setChartType LineXY
                     setDataEncoding text
                     setChartTitle "Projected Christmas Cheer for 2007"

                     setGrid $ makeGrid { xAxisStep = 3.333,
                                          yAxisStep = 10,
                                          lineSegmentLength = Just 1,
                                          blankSegmentLength = Just 3 }

                     addAxis $ makeAxis { axisType = AxisLeft,
                                          axisRange = Just $ Range (0,100) (Just 50) }
                     addAxis $ makeAxis { axisType = AxisBottom,
                                          axisLabels = Just $ ["Dec 1st"] ++ blanks 4 ++ ["6th"] ++ blanks 18 ++ ["25th","26th"] ++ blanks 4 ++ ["Dec 31st"] }

                     addChartDataXY dataSeries3
                     addColor "458B00"

                     addChartDataXY dataSeries4
                     addColor "CD2626"

                     setLegend $ legendWithPosition ["2006","2007"] LegendRight

dataSeries3 :: [(Float,Float)]
dataSeries3 = zip [0,16.7,23.3,33.3,60,76.7,83.3,86.7,93.3,96.7,100] [30,45,20,50,15,80,60,70,40,55,80]

dataSeries4 :: [(Float,Float)]
dataSeries4 = zip [0,10,16.7,26.7,33.3] [50,10,30,55,60]

blanks x = take x $ repeat ""

Generates the following chart

Line Graph

Example 5 : Scatter Plot with Shape Markers

The code below

scatterPlotWithMarkers = getChartUrl $ do setChartSize 200 125
                                          setChartType ScatterPlot
                                          setDataEncoding simple
                                          addChartDataXY dataSeries5
                                          addAxis $ makeAxis { axisType = AxisBottom,
                                                               axisLabels = Just $ blanks 1 ++ ["1","2","3","4","5"] }
                                          addAxis $ makeAxis { axisType = AxisLeft,
                                                               axisLabels = Just $ blanks 1 ++ ["50","100"] }
                                          setGrid $ makeGrid { xAxisStep = 20, yAxisStep = 25 }

                                          addShapeMarker $ makeShapeMarker { shapeType  = ShapeSquare
                                                                           , shapeColor = "ff0000"
                                                                           , shapeSize  = 10 }

-- Reverse engineering sample data from webpage
dataSeries5 :: [(Int,Int)]
dataSeries5 = zip xseries yseries where
             xseries = map encSimpleReverse "984sttvuvkQIBLKNCAIipr3z9"
             yseries = map encSimpleReverse "DEJPgq0uov17_zwopQOD"

encSimpleReverse :: Char -> Int
encSimpleReverse c | ord c >= ord 'A' && ord c <= ord 'Z' = (ord c - ord 'A')
                   | ord c >= ord 'a' && ord c <= ord 'z' = 26 + (ord c - ord 'a')
                   | ord c >= ord '0' && ord c <= ord '9' = 52 + (ord c - ord '0')
                   | otherwise = -1

Generates the following chart.

Scatter Plot with Shape Markers

Metadata

Version

0.4.2

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows