Creating Terminal ASCII Line Charts in Elixir with asciichart
Are you looking for a simple way to create line charts in Elixir without any external dependencies? Look no further – the asciichart library has got you covered! In this article, we will explore how to create terminal ASCII line charts in Elixir using the asciichart library.
Installation
To get started, you’ll need to add asciichart
to the list of dependencies in your Elixir project’s mix.exs
file. Simply add the following line of code:
elixir
def deps do
[{:asciichart, "~> <version>"}]
end
Be sure to replace <version>
with the desired version of the library.
Usage
Creating a line chart with asciichart is incredibly easy. All you need is a list of data points. Here’s a simple example:
elixir
{:ok, chart} = Asciichart.plot([1, 2, 3, 3, 2, 1])
chart |> IO.puts()
The above code will generate the following line chart:
3.00 ┤ ╭─╮
2.00 ┤╭╯ ╰╮
1.00 ┼╯ ╰
You can also customize your line charts by providing additional options such as offset, height, padding, charset, and precision. For example:
elixir
{:ok, chart} = Asciichart.plot([1, 2, 5, 5, 4, 3, 2, 100, 0], height: 3, offset: 10, padding: "__")
chart |> IO.puts()
This code will produce the following customized line chart:
╭─> label
------
100.00 ┼ ╭╮
_50.00 ┤ ││
__0.00 ┼──────╯╰
--
---- ╰─> label padding
╰─> remaining offset (without the label)
Versioning
asciichart follows the SemVer (Semantic Versioning) standard for versioning. It is important to check the version of the library you are using and ensure compatibility with your code.
License
The asciichart library is licensed under the Apache License, Version 2.0. This means that you are free to use, modify, and distribute the library as per the terms of the license. For more details, please refer to the LICENSE file.
Conclusion
In this article, we have explored how to create terminal ASCII line charts in Elixir using the asciichart library. We discussed the installation process, basic usage, customization options, versioning, and licensing. With asciichart, you can easily visualize your data in the terminal without any external dependencies. So go ahead and create stunning line charts with ease!
If you have any further questions or want to learn more about asciichart, please don’t hesitate to ask.
References:
– asciichart on GitHub
– asciichart on Hex
Leave a Reply