Joost, Bedankt. I went wrong on the Event thing .. :-S
On Wed, Oct 21, 2009 at 9:47 PM, Joost Schouten (ml) <[email protected]>wrote: > oops, mixed up the jpg and png encoders. Obviously in the below example the > content type should be: "image/png" and to avoid confusion rename the > JPEGEncoder to PNGEncoder. > > cheers, Joost > > > Joost Schouten (ml) wrote: > >> Hi, >> >> Don't know about the chenille options, but creating one with JFreeChart >> [1] and returning a StreamResponse is fairly straightforward [2]. >> >> cheers, >> Joost >> >> [1] http://www.jfree.org/jfreechart/api/javadoc/index.html >> [2] >> >> private SunPNGEncoderAdapter JPEGEncoder = new SunPNGEncoderAdapter(); >> >> @Inject >> private ComponentResources resources; >> >> @OnEvent(value = "showGraph") >> private Object showGraph() throws Exception { >> >> PieDataset pieDataSet = .....; >> JFreeChart chart = ChartFactory.createPieChart("title", pieDataSet, >> true, false, false); >> BufferedImage chartImage = chart.createBufferedImage(chartWidth, >> chartHeight); >> final ByteArrayInputStream output = new >> ByteArrayInputStream(JPEGEncoder.encode(chartImage)); >> >> final StreamResponse response = new StreamResponse() { >> >> public String getContentType() { >> return "image/jpg"; >> } >> >> public InputStream getStream() throws IOException { >> try { >> return output; >> } catch (Exception e) { >> log.error(e); >> throw new IOException(e.getMessage()); >> } >> } >> >> public void prepareResponse(Response response) { >> } >> }; >> return response; >> } >> >> public String getGraphUrl() { >> Link link = resources.createEventLink("showGraph"); >> return link.toAbsoluteURI(); >> } >> >> >> ------------------in your *.tml ------------------- >> >> <img src="${graphUrl}"/> >> >> >> >> Fermin Da Costa Gomez wrote: >> >>> Hi, >>> >>> Having already wasted a couple of hours on this i thought i would put the >>> question to the list. >>> Does anybody have a snip that creates a pie chart? >>> >>> With chenille i can get the line and bar but a proper pie is, so far, >>> still >>> eluding me .. :-( >>> >>> Tia, >>> >>> Fermin DCG >>> >>> >>> >> >> > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > > -- “The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore all progress depends on the unreasonable man.” - George Bernard Shaw (1856 - 1950)
