manuel-rubio

manuel-rubio

I’m excited to introduce you to Plotto, a chart library created in 100% Elixir that generates SVG and PNG images. Yes, it’s not only generating SVG for interactive use in combination with LiveView, but you can also generate directly to PNG with the same image and send it vía email, Telegram, Slack, or whatever you need.

Plotto is a plot library, 100% Elixir, that’s focused on generating beautiful SVG charts and exporting the same chart to PNG when it’s needed — including the PNG rasterizer and TrueType font renderer, no external binaries or NIFs required.

It is very useful when you are developing a website and need to integrate SVG charts. Chart data items accept arbitrary HTML/SVG attributes (phx-click, data-*, etc.), so if you are using Phoenix LiveView you can attach events, actions, and feedback to individual bars/points — without Plotto depending on Phoenix or LiveView in any way.

If you need to export or generate PNG charts for email, PDF, or sending via Telegram, Slack, Mattermost, etc., Plotto.to_png/1 renders the same chart to a PNG binary, anti-aliased and with full Unicode text support (including accented characters like á, é, ñ) via a bundled DejaVu Sans font.

Charts can also show an optional title and a legend (one color swatch + name row per series), positioned in any of the four corners — see :title and :legend in Plotto.BarChart or Plotto.LineChart. Negative values and mixed positive/negative domains are fully supported with an automatic zero baseline.

It was created to be introduced in the project Conta.

Showing Posts 1 to 9

alvinkatojr

alvinkatojr

You are killling it, man! I can’t wait to dive into the source. This and press both look amazing! Good work!

MarcusRiemer

MarcusRiemer

Oh, this is very interesting, thank you for your contribution! I’m currently rendering my own charts for (effectively) a distribution of outcomes for a game with dice:

Could I switch to Plotto for this? I skimmed the examples and didn’t see an option to put labels above the bars, but maybe I’m missing something. The colours in my example change whenever the distribution switches from “target damaged” to “target defeated”. I think for that I would have to pass two seperate series?

manuel-rubio

manuel-rubio OP

I’m using both in Conta :wink:

manuel-rubio

manuel-rubio OP

Done! New version 0.4.0 supports that:

categories = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "> 10"]

# 0..4 en la primera serie (rosa), 5..> 10 en la segunda serie (azul)
first_values = [9.3, 6.7, 8.4, 10.1, 12.0, 0, 0, 0, 0, 0, 0]
second_values = [0, 0, 0, 0, 0, 14.0, 9.4, 8.5, 7.2, 5.7, 8.6]

data = [
  %{
    name: "0-4 Range",
    data: Enum.zip_with(categories, first_values, fn cat, val -> %{label: cat, value: val} end)
  },
  %{
    name: "5+ Range",
    data: Enum.zip_with(categories, second_values, fn cat, val -> %{label: cat, value: val} end)
  }
]

pink = "#F06292"
blue = "#4E79A7"

chart =
  Plotto.BarChart.new!(
    data,
    mode: :stacked,
    colors: [pink, blue],
    label: fn item ->
      if item.value > 0 do
        "#{item.value}%"
      end
    end,
    width: 700,
    height: 400
  )

svg = Plotto.to_svg!(chart)
png = Plotto.to_png!(chart)

File.write!("two_color_bars.svg", svg)
File.write!("two_color_bars.png", png)

Here you go. The proof:

MarcusRiemer

MarcusRiemer

I started integrating Plotto and just stumbled over this: Plotto.LineChart — plotto v0.4.0

data uses the same multi-series shape as Plotto.BarChart, but today only the first series is drawn — full multi-series line rendering (multiple lines) is planned for a future release

Unluckily for me I do have line charts that look like this:

I could find another way to represent same-faction series than dashing, but the multi-series line chart have been exactly the chart I wanted to move to plotto in order to be able to render them for og:images.

Any ETA on that “future release”? :innocent:

manuel-rubio

manuel-rubio OP

Of course, but I don’t understand exactly what do you expect and what’s the issue? :stuck_out_tongue:

manuel-rubio

manuel-rubio OP

Done! New version 0.5.0

data = [
  %{
    name: "Elektrogriff (Gewitterbote)",
    dashed: true,
    color: "#9B59B6",
    data: [
      %{label: "1", value: 12},
      %{label: "2", value: 49},
      %{label: "3", value: 74},
      %{label: "4", value: 87},
      %{label: "5", value: 98}
    ]
  },
  %{
    name: "Sturmbogen (Wüstenjägerin)",
    color: "#8E44AD",
    data: [
      %{label: "1", value: 0},
      %{label: "2", value: 12},
      %{label: "3", value: 26},
      %{label: "4", value: 49},
      %{label: "5", value: 63},
      %{label: "6", value: 75},
      %{label: "7", value: 80},
      %{label: "8", value: 96}
    ]
  },
  %{
    name: "Jagddolch (Wüstenjägerin)",
    color: "#4A235A",
    data: [
      %{label: "1", value: 0},
      %{label: "2", value: 1},
      %{label: "3", value: 5},
      %{label: "4", value: 12},
      %{label: "5", value: 25},
      %{label: "6", value: 27},
      %{label: "7", value: 40},
      %{label: "8", value: 50},
      %{label: "9", value: 52},
      %{label: "10", value: 63}
    ]
  }
]

chart =
  Plotto.LineChart.new!(
    data,
    legend: :right_top,
    stroke_width: 3,
    width: 700,
    height: 450
  )

svg = Plotto.to_svg!(chart)
png = Plotto.to_png!(chart)

svg_path = Path.join(__DIR__, "weapons_chart.svg")
png_path = Path.join(__DIR__, "weapons_chart.png")

File.write!(svg_path, svg)
File.write!(png_path, png)

IO.puts("Successfully generated:")
IO.puts(" - SVG: #{svg_path}")
IO.puts(" - PNG: #{png_path}")

MarcusRiemer

MarcusRiemer

This is wonderful! I had some time yesterday and put Plotto to use at Wüstenjägerin gegen Gewitterbote · Summoners Compendium (linked page shows embedded SVG, is in german and is a technically unreleased feature that may still be buggy) and as png for the og:image:

I made minor CSS tweaks to show labels and axis even in darkmode:

/* Relies on Daisy UI, not portable */
.plotto-embed .plotto-axis {
  stroke: var(--color-base-300);
}

/* Maybe worth porting over: bridges the gap between HTML color for text and svg */
.plotto-embed .plotto-label,
.plotto-embed .plotto-legend,
.plotto-embed text {
  fill: currentColor;
}

Asking you for features has been so scarily effective, that I am almost hesitant to propose more. Please don’t feel pressured, these are things that would delight me, but I am very happy as is:

  1. Change the legends orientation to horizontal when being plotted under or over the graph. The current layout works well, but I do see this as an option to reduce empty whitespace by plotting my up to 4 options below the graph in a horizontal layout.
  2. Configuration option to add target values for the y axis. In my case I would like to always go to 100.
  3. Configuration option to add a suffix to the values (y-axis label and <title> on circles), in my case this would be a %.
  4. Configuration option to show horizontal guidelines with the y axis labels.
manuel-rubio

manuel-rubio OP

Released v0.6.0 :slight_smile:

Don’t worry, it’s satisfactory that someone uses the library. Don’t forget to give a star to the GitHub project :stuck_out_tongue:

The features:

Horizontal Legend Layout & Centre Alignments

Allows displaying legends horizontally side-by-side (legend_orientation: :horizontal) when placed at the top or bottom of the chart, along with centred positions (:top_center, :bottom_center). This saves significant lateral canvas space on wide charts with lengthy series names.

Y-Axis Target Bounds & Guide Lines

Enables defining explicit minimum and maximum target bounds (y_max, y_min) with configurable soft expansions (y_max_soft, y_min_soft). It also introduces horizontal reference guide lines (y_max_guide, y_min_guide) with customizable line styles and colours to highlight specific goals or critical thresholds.

Value Prefix & Suffix Formatting

Adds support for prepending prefixes (prefix: “$”, “€”) and appending suffixes (suffix: “%”, “k”, " USD") to numeric values. These formats are automatically and consistently applied across Y-axis tick labels, point/bar tooltips, and element top labels, with proper handling of negative numbers.

Horizontal & Vertical Grid Guidelines

Introduces customizable grid lines across the plotting canvas (y_guidelines and x_guidelines), projecting reference lines from axis tick marks. They can be toggled on with theme defaults or styled with custom colours and strokes (:dotted, :dashed, :solid) to facilitate reading and comparing data points.

data = [
  %{
    name: "Elektrogriff (Gewitterbote)",
    dashed: true,
    color: "#9B59B6",
    data: [
      %{label: "1", value: 12},
      %{label: "2", value: 49},
      %{label: "3", value: 74},
      %{label: "4", value: 87},
      %{label: "5", value: 98}
    ]
  },
  %{
    name: "Sturmbogen (Wüstenjägerin)",
    color: "#8E44AD",
    data: [
      %{label: "1", value: 0},
      %{label: "2", value: 12},
      %{label: "3", value: 26},
      %{label: "4", value: 49},
      %{label: "5", value: 63},
      %{label: "6", value: 75},
      %{label: "7", value: 80},
      %{label: "8", value: 96}
    ]
  },
  %{
    name: "Jagddolch (Wüstenjägerin)",
    color: "#4A235A",
    data: [
      %{label: "1", value: 0},
      %{label: "2", value: 1},
      %{label: "3", value: 5},
      %{label: "4", value: 12},
      %{label: "5", value: 25},
      %{label: "6", value: 27},
      %{label: "7", value: 40},
      %{label: "8", value: 50},
      %{label: "9", value: 52},
      %{label: "10", value: 63}
    ]
  }
]

chart =
  Plotto.LineChart.new!(
    data,
    legend: :bottom_center,
    legend_orientation: :horizontal,
    y_max: 100,
    suffix: "%",
    y_guidelines: true,
    stroke_width: 3,
    width: 700,
    height: 450
  )

svg = Plotto.to_svg!(chart)
png = Plotto.to_png!(chart)

svg_path = Path.join(__DIR__, "weapons_chart.svg")
png_path = Path.join(__DIR__, "weapons_chart.png")

File.write!(svg_path, svg)
File.write!(png_path, png)

IO.puts("Successfully generated:")
IO.puts(" - SVG: #{svg_path}")
IO.puts(" - PNG: #{png_path}")

— All posts loaded —

Where Next? Top

Trending in Announcing Top

restlessronin
The repo is at GitHub - cyberchitta/openai_ex: Community maintained Elixir library for OpenAI API · GitHub. Docs are at OpenaiEx User Gu...
152 12366 136
New
type1fool
WebAuthnLiveComponent WebAuthnComponents See this post about renaming the package. Passwordless authentication for Phoenix LiveView app...
New
GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
woylie
I released Doggo, a collection of unstyled Phoenix components. https://github.com/woylie/doggo Features Unstyled Phoenix components....
New
ahamez
Hi everyone, I’ve been working on this protobuf library for 3 years. We use it in the company I work for, EasyMile, to communicate with ...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
kip
I’ll shortly be launching Text, a nascent text analysis library. Current functionality In this early version (not ready for prime time) ...
New

Other Trending Topics Top

budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
budgie
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with. But I don’t use it anymore. Serverless was the promis...
New
Null-logic-0
What IDE or editor are you using for Elixir development? Personally, I use Zed, and I really like it, but sometimes I wish there were a ...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews