asciichart v1.1.0 Asciichart

ASCII chart generation.

Ported to Elixir from https://github.com/kroitor/asciichart

Link to this section Summary

Functions

Generates a chart for the specified list of numbers

Link to this section Functions

Link to this function plot(series, cfg \\ %{})
plot([number()], %{optional(atom()) => any()}) :: String.t()

Generates a chart for the specified list of numbers.

Optionally, the following settings can be provided:

  • :offset - the number of characters to set as the chart’s offset (left)
  • :height - adjusts the height of the chart
  • :padding - one or more characters to use for the label’s padding (left)
  • :charset - a customizable character set

Examples

iex> Asciichart.plot([1, 2, 3, 3, 2, 1])
{:ok, "3.00 ┤ ╭─╮   \n2.00 ┤╭╯ ╰╮  \n1.00 ┼╯   ╰  \n          "}

# should render as

3.00  
2.00  
1.00    

iex> Asciichart.plot([1, 2, 6, 6, 2, 1], height: 2)
{:ok, "6.00 ┤       \n3.50 ┤ ╭─╮   \n1.00 ┼─╯ ╰─  \n          "}

# should render as

6.00 
3.50  
1.00  

iex> Asciichart.plot([1, 2, 5, 5, 4, 3, 2, 100, 0], height: 3, offset: 10, padding: "__")
{:ok, "    100.00    ┤      ╭╮  \n    _50.00    ┤      ││  \n    __0.00    ┼──────╯╰  \n                    "}

# should render as

    100.00          
    _50.00          
    __0.00    


# Rendering of empty charts is not supported

iex> Asciichart.plot([])
{:error, "No data"}