HORIZON HASKELLDocslts/ghc-10.0.xaa25b892026-10-10Search names, modules, packages, or :: a typeCtrl K

GHC 10.0.0.20260917 · lts/ghc-10.0.x · aa25b89 · 2026-10-10

Modulegranite-0.7.4.0GHC2021

Granite.String

A String-based interface to the Granite plotting library. This module provides the same functionality as Granite but uses String instead of Text for easier use in simple scripts and educational contexts.

Basic Usage

Create a simple scatter plot:

import Granite.String

main = do
  let points = [(x, sin x) | x <- [0, 0.1 .. 6.28]]
      chart = scatter [series "sin(x)" points] defPlot
  putStrLn chart

Note on Performance

This module internally converts between String and Text. For performance-critical applications with large datasets, consider using the Granite module directly which works with Text natively.

Terminal Requirements

This library requires a terminal that supports:

  • Unicode (specifically Braille patterns U+2800-U+28FF)

  • ANSI color codes

  • Monospace font with proper Braille character rendering

  • 6 types
  • 11 values

Plot Configuration

2 declarations
datadata Plot
#

Plot configuration parameters.

Controls the appearance and layout of generated charts.

Constructors

valuedefPlot :: Plot
#

Default plot configuration.

Creates a 60×20 character plot with reasonable defaults:

defPlot = Plot
  { widthChars   = 60
  , heightChars  = 20
  , leftMargin   = 6
  , bottomMargin = 2
  , titleMargin  = 1
  , xBounds      = (Nothing, Nothing)
  , yBounds      = (Nothing, Nothing)
  , plotTitle    = ""
  , legendPos    = LegendRight
  , colorPalette = [BrightBlue, BrightMagenta, BrightCyan, BrightGreen, BrightYellow, BrightRed, BrightWhite, BrightBlack]
  , xFormatter   = \_ _ d -> show d
  , yFormatter   = \_ _ d -> show d
  , xNumTicks    = 2
  , yNumTicks    = 2
  }

Data Preparation

23 declarations
valueseries
  1. :: String

    Name of the series (appears in legend)

  2. -> [(Double, Double)]

    List of (x, y) data points

  3. -> (String, [(Double, Double)])
#

Create a named data series for multi-series plots.

let s1 = series "Dataset A" [(1,2), (2,4), (3,6)]
    s2 = series "Dataset B" [(1,3), (2,5), (3,7)]
    chart = scatter [s1, s2] defPlot
datadata Bins
#

Defines the binning parameters.

Instances2Eq, Show
  • Eq BinsDefined in granite-0.7.4.0 · Granite
  • Show BinsDefined in granite-0.7.4.0 · Granite
datadata Color
#

A 24-bit RGB colour.

Constructors

Instances3Eq, Read, Show
  • Eq ColorDefined in granite-0.7.4.0 · Granite.Color
  • Read ColorDefined in granite-0.7.4.0 · Granite.Color
  • Show ColorDefined in granite-0.7.4.0 · Granite.Color
valuebins
  1. :: Int

    Number of bins (will be clamped to minimum 1)

  2. -> Double

    Lower bound

  3. -> Double

    Upper bound

  4. -> Bins
#

Create a bin configuration for histograms.

bins 10 0 100  -- 10 bins from 0 to 100
bins 20 (-5) 5 -- 20 bins from -5 to 5

Formatting

1 declaration
typetype LabelFormatter = AxisEnv -> Int -> Double -> String
#

Axis-aware, width-limited, tick-label formatter.

Given: * axis context * a per-tick width budget (in terminal cells) * and the raw tick value. returns the label to render.

Chart Types

8 declarations
valuescatter
  1. :: [(String, [(Double, Double)])]

    List of named data series

  2. -> Plot

    Plot configuration

  3. -> String

    Rendered chart as String

#

Create a scatter plot from multiple data series.

Each series is rendered with a different color and pattern. Points are plotted using Braille characters for sub-character resolution.

Example
let points1 = [(x, x^2) | x <- [-3, -2.5 .. 3]]
    points2 = [(x, 2*x + 1) | x <- [-3, -2.5 .. 3]]
    chart = scatter [series "y = x²" points1,
                     series "y = 2x + 1" points2] defPlot
valuelineGraph
  1. :: [(String, [(Double, Double)])]

    List of named data series

  2. -> Plot

    Plot configuration

  3. -> String

    Rendered chart as String

#

Create a line graph connecting data points.

Similar to scatter but connects consecutive points with lines. Points are automatically sorted by x-coordinate before connecting.

Example
let sine = [(x, sin x) | x <- [0, 0.1 .. 2*pi]]
    cosine = [(x, cos x) | x <- [0, 0.1 .. 2*pi]]
    chart = lineGraph [series "sin" sine, series "cos" cosine] defPlot
valuebars
  1. :: [(String, Double)]

    List of (category, value) pairs

  2. -> Plot

    Plot configuration

  3. -> String

    Rendered chart as String

#

Create a bar chart from categorical data.

Each bar is colored differently and labeled with its category name.

Example
let fruits = [("Apple", 45.2), ("Banana", 38.1), ("Orange", 52.7)]
    chart = bars fruits defPlot { plotTitle = "Fruit Sales" }
valuestackedBars
  1. :: [(String, [(String, Double)])]

    Categories with stacked components

  2. -> Plot

    Plot configuration

  3. -> String

    Rendered chart as String

#

Create a stacked bar chart.

Each category can have multiple stacked components.

Example
let sales = [("Q1", [("Product A", 100), ("Product B", 150)]),
             ("Q2", [("Product A", 120), ("Product B", 180)])]
    chart = stackedBars sales defPlot
valuehistogram
  1. :: Bins

    Binning configuration

  2. -> [Double]

    Raw data values to bin

  3. -> Plot

    Plot configuration

  4. -> String

    Rendered chart as String

#

Create a histogram from numerical data.

Data is binned according to the provided Bins configuration.

Example
import System.Random

-- Generate random normal-like distribution
let values = take 1000 $ randomRs (0, 100) gen
    chart = histogram (bins 20 0 100) values defPlot
valuepie
  1. :: [(String, Double)]

    List of (category, value) pairs

  2. -> Plot

    Plot configuration

  3. -> String

    Rendered chart as String

#

Create a pie chart showing proportions.

Values are normalized to sum to 100%. Negative values are treated as zero.

Example
let browsers = [("Chrome", 65), ("Firefox", 20), ("Safari", 10), ("Other", 5)]
    chart = pie browsers defPlot { plotTitle = "Browser Market Share" }
valueheatmap
  1. :: [[Double]]

    2D matrix of values (rows × columns)

  2. -> Plot

    Plot configuration

  3. -> String

    Rendered chart as String

#

Create a heatmap visualization of a 2D matrix.

Values are mapped to a color gradient from blue (low) to red (high).

Example
let matrix = [[x * y | x <- [1..10]] | y <- [1..10]]
    chart = heatmap matrix defPlot { plotTitle = "Multiplication Table" }
valueboxPlot
  1. :: [(String, [Double])]

    Named datasets

  2. -> Plot

    Plot configuration

  3. -> String

    Rendered chart as String

#

Create a box plot showing statistical distributions.

Displays quartiles, median, and min/max values for each dataset.

Example
let data1 = [1.2, 2.3, 2.1, 3.4, 2.8, 4.1, 3.9]
    data2 = [5.1, 4.8, 6.2, 5.9, 7.1, 6.5, 5.5]
    chart = boxPlot [("Group A", data1), ("Group B", data2)] defPlot

The box plot displays:

  • Box: First quartile (Q1) to third quartile (Q3)

  • Line inside box: Median (Q2)

  • Whiskers: Minimum and maximum values