 | GoogleChart-0.2: Generate web-based charts using the Google Chart API | Contents | Index |
|
|
|
|
|
| Description |
This module is for generating web-based charts using Google's Chart API:
http://code.google.com/apis/chart/. Its output is URLs that will resolve
to a PNG image of the resulting chart.
Most of the functions in this module, with names like setFoo, take a Chart
as an argument and produce a new Chart with the specified attribute added.
These calls are designed to be chained together. See the example below.
Charts are represented as a hierarchy of type classes so that parameters
that only affect a specific chart type are only available to that chart type.
putStrLn "URL for your chart:"
putStrLn $ chartURL $
setSize 400 257 $
setTitle "My Chart" $
setData (encodeDataSimple [[1..20]]) $
setLegend ["1 to 20"] $
newLineChart
This produces:
http://chart.apis.google.com/chart?chs=400x257&chtt=My+Chart&chd=s%3aBCDEFGHIJKLMNOPQRSTU&chdl=1+to+20&cht=lc
Remaining features to implement:
- lxy line charts
- chbh bar charts
- scatter plots
- background/fill colors
- all style attributes
|
|
| Synopsis |
|
|
|
|
| Chart basics
|
|
| These functions and types are shared by all chart types.
|
|
| class Chart c |
| The type class underneath all Charts.
| | Instances | |
|
|
| chartURL :: Chart c => c -> String |
| Construct the URL used to show the chart.
|
|
| setSize :: Chart c => Int -> Int -> c -> c |
| Set the width and height, in pixels, of the resulting image.
|
|
| setTitle :: Chart c => String -> c -> c |
| Set the title of the chart.
|
|
| setTitleOpts |
| :: Chart c | | | => String | Color of the text.
| | -> Int | Size of the text.
| | -> c | | | -> c | | | Set options for the display of the title of the chart.
|
|
|
| setData :: Chart c => ChartData -> c -> c |
| Set the data displayed by the chart.
|
|
| Chart data
|
|
| There are multiple options for encoding chart data. See
http://code.google.com/apis/chart/#chart_data for more details on
the tradeoffs of the different encoding options.
|
|
| data ChartData |
| All the encoding methods produce ChartData, which is usable by setData.
| Instances | |
|
|
| encodeDataSimple :: [[Int]] -> ChartData |
| Encode data using the "simple" encoding, which maps each input value
to a single letter in the URL. This produces minimal URLs but doesn't have
as lot of resolution. Input values must be in the range 0 <= x <= 61.
Values outside the valid input range will be considered missing data.
|
|
| encodeDataText :: RealFrac a => [[a]] -> ChartData |
| Encode data using the "text" encoding, which maps each input value to
its string representation (e.g. "3.4") in the URL. This has more
resolution than simple encoding but produces larger URLs. Input values must
be in the range 0 <= x <= 100. Values outside the valid input range will
be considered missing data. Values with more than one decimal place of
resolution will be rounded.
|
|
| encodeDataExtended :: [[Int]] -> ChartData |
| Encode data using the "extended" encoding, which maps each input value
to a two-character pair in base 64. This has more resolution than text
encoding and is more compact. Input values must be in the range 0 <= x <=
4095. Values outside the valid input range will be considered missing
data.
|
|
| setDataColors :: Chart c => [String] -> c -> c |
| Set data set colors. The nth color specified here colors the nth data
set in the ChartData passed to setData. See
http://code.google.com/apis/chart/#line_bar_pie_colors for more
information.
|
|
| Chart features
|
|
| Legends
|
|
| class Chart c => LegendChart c |
| LegendChart represents charts that can display legends with setLegend.
| | Instances | |
|
|
| setLegend :: LegendChart c => [String] -> c -> c |
| Set the legend for the corresponding data sets. The colors are taken
from the data set colors.
|
|
| Axis labels
|
|
| The order of elements in the lists passed to these functions matter:
If the first AxisType passed to setAxisTypes is AxisBottom, then
the first set of labels passed to setAxisLabels refers to that bottom
axis.
|
|
| class Chart c => AxisLabelChart c |
| AxisLabelChart represents charts that can display axis labels.
| | Instances | |
|
|
| setAxisTypes :: AxisLabelChart c => [AxisType] -> c -> c |
| Set which axes to display. Repeating an AxisType produces multiple
sets of labels on that axis.
|
|
| data AxisType |
| Where to display an axis.
| | Constructors | | AxisBottom | | | AxisTop | | | AxisLeft | | | AxisRight | |
|
|
|
| setAxisLabels :: AxisLabelChart c => [[String]] -> c -> c |
| Set axis labels. The nth list of strings in the argument sets the labels
for the nth axis specified with setAxisTypes. An empty list of strings
skips labelling the corresponding axis.
|
|
| setAxisLabelPositions :: AxisLabelChart c => [[Int]] -> c -> c |
| Set axis label positions. The nth list of Ints in the argument sets the
positions for the nth axis specified with setAxisTypes. An empty list
skips setting position for the corresponding axis.
|
|
| setAxisRanges :: AxisLabelChart c => [(Int, Int)] -> c -> c |
| Set axis ranges. The nth pair of Ints in the argument sets the range
for the nth axis specified with setAxisTypes.
|
|
| data AxisAlignment |
| Text alignment for labels on an axis.
| | Constructors | | AlignLeft | | | AlignCenter | | | AlignRight | |
|
|
|
| setAxisStyles :: AxisLabelChart c => [(String, Int, AxisAlignment)] -> c -> c |
| Set axis styles. The nth element in the argument sets the style for the
nth axis specified with setAxisTypes. Each style is a tuple of
(color, font size, text alignment).
|
|
| Specific chart types
|
|
| Line charts
|
|
| data LineChart |
Instances | |
|
|
| newLineChart :: LineChart |
|
| Pie charts
|
|
| data PieChart |
Instances | |
|
|
| newPieChart :: PieStyle -> PieChart |
|
| data PieStyle |
|
|
| setLabels :: [String] -> PieChart -> PieChart |
| Set labels for the different data points on the chart.
Specify missing values by passing an empty string.
|
|
| Bar charts
|
|
| data BarChart |
Instances | |
|
|
| newBarChart :: Orientation -> BarStyle -> BarChart |
|
| data Orientation |
|
|
| data BarStyle |
|
|
| Venn diagrams
|
|
| data VennDiagram |
| Venn diagram data is specified in a particular format. There should be
exactly seven data values, which represent, in order:
circle A size, circle B size, circle C size,
A/B overlap, A/C overlap, B/C overlap,
A/B/C overlap.
| Instances | |
|
|
| newVennDiagram :: VennDiagram |
|
| Produced by Haddock version 0.8 |