6

I want to plot a bar graph in elixir and save it as an image.

Is there any good charting library for doing this ?

I tried searching on elixir.libhunt.com and github.com/h4cc/awesome-elixir, but didn't find a single package for my need.

Thanks in advance.

vinzee93
  • 91
  • 7
  • 1
    You can use [edg_chart](https://github.com/psyeugenic/eplot/blob/master/src/egd_chart.erl) from Erlang for bar chart. –  Dec 07 '16 at 08:39
  • 2
    Welcome to StackOverflow! Asking to find a library is considered off-topic. If you had any questions about a specific library, that would be on-topic. – Justin Wood Dec 07 '16 at 14:03

3 Answers3

6

Yes - you can interface to gnuplot with gnuplot-elixir

As as example, to generate the bar graph in this answer - the code would be:

import Gnuplot

chart = [
      [:set, :term, :png, :size, '512,512'],
      [:set, :output, Path.join("/tmp", "barchart.PNG")],
      [:set, :boxwidth, 0.5],
      ~w(set style fill solid)a,
      [:plot, "-", :using, '1:3:xtic(2)', :with, :boxes]
    ]

dataset = [[0, "label", 100], [1, "label2", 450], [2, "bar label", 75]]

plot(chart, [dataset])

devstopfix
  • 6,698
  • 4
  • 34
  • 32
4

I don't think there's any such control for Elixir--nothing native anyway. Graphics is not exactly in Elixir's wheelhouse. However, I think you could probably build something yourself with wxErlang. You can see what sorts of things you can do with wxErlang in Elixir by typing :wx.demo() from within iex. I don't know of a graph primitive in wxErlang but it may be that I simply haven't found it yet.

Onorio Catenacci
  • 14,928
  • 14
  • 81
  • 132
0

As an update to this question, you can now use the vega_lite package and LiveBook to easily plot with Elixir.

https://livebook.dev/

https://github.com/livebook-dev/vega_lite

bmitc
  • 357
  • 1
  • 9