JfreeCharts and ToneGodGui

Hi !
I’ve plane to show some Jfreecharts plots using tonegodgui to show datas computed in the game.
I actually show JfreeCharts’ generated jpeg on an element using setTextureAtlasImage and it works fine. The problem i have is that i need to update my jpeg. I thaught i could overwrite it on the disk and then load it again using a getAssetManager().loadTexture, but it always ends up with the first one.

Thanks for helping me guys :smile:

Thats because assets are cached, check DesktopAssetManager.clearCache() and the associated methods. Also note that for a distributed app the assets folder is not a folder anymore but a jar file so you cannot change files there in a distributed app, you need to make a folder in the user directory and add that to the assetmanager via a filelocator.

Also you could consider just keeping the image in memory instead of writing it to the hard drive.
As far as I remember jFreeChart can output to an outputStream. You could convert this stream to a JME Image and use this in a texture in your material

Ok thanks for your answers. Yes the outputStream method seems more clever.
How do I convert a stream to a JME image then ?

look in the ImageToAWTClass. It converts AWT BufferedImage to JME Images. I guess there are ways to convert an outputstream to a BufferedImage

1 Like

OK thanks I’ll try that and give you some feedback soon.

ImageIO.read should do the trick

Ok thx guys it works ! But i still have some issues, here is a sample of the code i used :

try {
int i = 196000;
InWind = new PipedInputStream(i);
outWind = new PipedOutputStream(InWind);
} catch …
( … )
ChartUtilities.writeChartAsPNG(outWind, xylineChart, width , height);
outWind.flush();
( … )

// here i update the graph in an overided onChange() function of a slider in order to interact with the graph :

AWTLoader loader = new AWTLoader();

try {
Image ImgStretch = null;
// this is where it start to be ugly i’ve made a loop to “wait” for the image.
while (ImgStretch == null) {
ImgStretch = loader.load(Plot.InStretch, true);
}
Texture Texture1;
Texture1 = new Texture2D(ImgStretch);
showPlot1.setTextureAtlasImage(Texture1, “x=0|y=0|w=640|h=480”);
window.addChild(showPlot1);
showPlot1.showWithEffect();
} catch (Exception e) {e.printStackTrace();}

So i didn’t use buffered image but entire image in a pipedstream.

I still have a problem, sometimes i get weird noised image (like an old cathodic screen) instead of my graphs the program freeze and I cant have no error log or exception to caught, as if ImgStretch was not null, but was not a well written image.

What do you think about it ? I don’t know what to do.

EDIT:
Ok i used xylineChart.createbufferedImage ( i didnt see it earlier ! ) then in awt.load(). and it works like a charm.
Still, i dont get it with the piped stream;