Asciichart (asciichart v1.2.0)

ASCII chart generation.

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

Summary

Functions

Generates a chart for the specified list of numbers.

Functions

Link to this function

plot(series, cfg \\ %{})

@spec 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
  • :precision - number of fractional digits to keep for floating-point values

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    

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

# should render as

    100.000           
    _50.000           
    __0.000     


# Rendering of empty charts is not supported

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