Does anyone know a mean to "render" plots or at least trees in console mode (draw it in the console)?
I would be able to render small plots at end of a very long process, by drawing some figures in ASCII mode, in order to have a geeky & fun view of some stats collected into the process.
I would be pleased to discover a library which does that, and I would keep the process 100% java, no shell-hack or third-party software.
-- EDIT
@lbalazscs and @Fortega made interesting answers, but the background of my question is to know if it exists such a library, and I will add some details I missed the first time :
The output should be able to display trees, binary trees (linked by @lbalazscs here), but also simple graphs such as bargraphs or so.
I will let this question "unanswered" for a while, and if there is no probant answer, @lbalazscs will get the point ;)
In Java, plotting of graph is done by using several topics of core Java. For plotting, we use swing, awt, and awt. geom. We use Swing package to use Jlabel, JButtons, and JPanel in our program.
The Java Graph class relies on an underlying Vertex class with the following behaviors: a constructor that sets data to the passed in inputData and sets edges to an empty ArrayList. an . addEdge() method that takes a vertex and weight and adds an edge to edges.
Usually, we implement graphs in Java using HashMap collection. HashMap elements are in the form of key-value pairs. We can represent the graph adjacency list in a HashMap. A most common way to create a graph is by using one of the representations of graphs like adjacency matrix or adjacency list.
You can print ascii trees with minimal code. See the second answer to this question: How to print binary tree diagram?
(the second answer because this one is not only for binary trees)
For people coming here looking for a pure Java tree drawing library: I recommend text-tree, which draws trees like this (and other styles, a lot of possible config if you need it):
some text
├─── more text
├─── and more
│ ├─── still more
│ ╰─── more
╰─── the end
Full disclosure: I am the author of text-tree.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With