Creating bar charts

Is there anyone here who has done bar charts or other statistics representations? Preferably in combination with Lemur.

I need to show progress of the evolving little guys in my game Unga Munga over time. Stuf like: how many survive? How many attack others? How many use tools?

I also want to give the player some insight in the ‘character’ of a selected guy. This could be a pie chart showing the percentages in which it choose to run, fight or push rocks.

For me, I know Java2D very well and would be tempted to use it here. It’s pretty trivial to get a java.awt.Graphics object from a BufferedImage and then you have the full capabilities of Java2D. …then just convert that to a texture.

A perhaps slightly more light-weight option would be to paint to a JME ImageRaster but then you lack all of the Java2D features.

If the thought of sending new texture data every time you update is distasteful (though it’s really not a big deal) or if you really have your heart set on real geometry then things get more complicated. Bar charts are straight forward. Anything more complicated involves different tricks.

As a different trick, what about a list of vertical lemur progress bars grouped together in a Container with a BoxLayout that grows horizontally?

Yeah, the bar graph is the easy one, I think.

To follow on pspeed’s idea, JFreeChart or similar chart library. At least the jFreeChart is even by default a BufferedImage at the end. You can even hook a custom graphic builder there to translate the charts directly to jME for creating (scalable) graphics instead going through BufferedImage first for raster textures.

I love the idea of Jva2D or even raw image drawing interesting. Would that work in a sperate thread?

JFreeChart would be great if it allows for styling. Would that work in a seperate thread?

Only when you are trying to show it (whether you chose to draw it directly as quads etc or otherwise attaching it to the scene graph) you need to use the render thread. But for that you have the Application.enqueue(). Other than that, you can design it to run in as many threads as you want. With the limitation of what i.e. JFreeChart supports then.

In my effort to stay as close to vanilla JME I decided the following solution:

I created a custom mesh that I put in Lines-mode. In lines mode every two vertices make up a line. Exactly what I needed for my bar charts.

If you promise not to notice that I have little work done on the layout and styling of my interface, you can have a look:

It is the red graph. It shows the number of times guys attacked each other per generation. This solution is very fast. Further styling will follow.

…btw: it says Fittness Kills. That is not on purpose. Even though I think it does.

5 Likes