How to create pie charts and present in html reports - java

how to generate pie charts based on the data in the XML and present it using html.
XML contains steps related to test case steps and result of each steps.
The pie charts should show the total no of steps failed and passed.
I have no idea how to use charts in reports , tried to google it but could not get from where to start and also confused.
can anybody help me or guide me in the right direction.
forgot to mention that i am using xslt to present data in html , how to do in that scenario.
thanks in advance.

I am biased towards JfreeChart, pretty easy API to learn and one can create complex charts with some exposure to the API which is documented well enough.
In your case, the data source will be xml and output can be seen on the web.

you can try morris for generating chart
http://www.oesmith.co.uk/morris.js/
Try to extract data from xml file using DOM parser a good tutorial can be found here. http://www.mkyong.com/java/how-to-read-xml-file-in-java-dom-parser/
Use the extracted data in html page to make an array and render it using Morris.js
Comment if you need further clarification

There are lots of libraries available to draw charts.
-JasperReports
-iReport
-DataVision
-jsCharts
-highCharts
see here for more

Related

Convert multiple files into PDF

My questions is rather theoretical. I need to implement an application that takes different file extensions such as [asp,bmp,doc,docx,html,jpg,pdf,pdf,png,pptx,sql,txt,xls,xlsx] and converts them all into a consecutive PDF file for print.
I did my research in terms of coding and found multiple libraries that do the job
such as Apache POI, iText, aspose.pdf.jar and others I tested them out on individual portions of the idea. They work great but require a lot of women-hours to implement the desired application. My question is, is there anything more complete that will speed up the job. For example a library such as apache POI that does not require specifying every single padding and background color.
Any suggestions are appreciated.
As per my knowledge and experience not a single API is present there who provide all solution without this. Because of that we need to use Apache POI, iText, aspose.pdf.jar , FOP.
In java(using jquery as per my knowledge) you are able take snapshot of rendered page using stream which you will need to proceed at serverside and generate PDF which generate pdf file same like html page without any extra formatting but it having limitation that you can't use landscape. If page data is big then it shrinks pdf which causes small font(in very large page even you unable to read pdf).

library to bring a pdf to code

I have the need to create some pdf through java code, pdf templates are fixed and are very complex too. Each pdf represents a module and I have to fill it with informations I get from other sources in my application and finally create the complete pdf.
So, is there a library which, given a pdf, scans it and creats some java code which will eventually create it back? This way once I get the pdf template in java code I just have to edit it adding my informations and create it back.
You can check these 2 link it's have all information regarding PDF CRUD operation.
How to read PDF files using Java?
http://mrbool.com/how-to-create-write-and-read-pdf-files-using-pdfone-and-java/27058
I have used with success iText http://itextpdf.com/ for various tasks involving creating, parsing and modifying pdf files. Please not that this one is not free for commercial use and the pricing isn't cheap either.
However, your question is a possible duplicate of the folowing one, so be sure to check the answers there:
https://stackoverflow.com/questions/6118635/what-is-the-best-pdf-open-source-library-for-java
itext is one of best approach for your need..
itext API'S

How to create Report from DB information in PDF format without using jasper

I want to create reports in PDF using the data available in database. I want to do some data manipulation and use the charts and details to be shown in pdf to the user.Suppose say there are 2 columns in DB a and b . I want to show in the PDF, the value of a and b and the addition of a and b. What i can use to generate this pdf report?
I thought of using jasper, but i donot want to use it. Instead is there any other logic in java that can help to solve this problem. Please suggest with examples.
Thanks
Birt is a tool that can be used to generate all sorts of reports. There are plugins for Eclipse that you can use to help you get going and you can definitely add logic in Java. It can output your report in multiple formats including PDF, HTML, and I believe even Word docs.
If you've used Eclipse before you should be able to figure out the basics, but it can get as complicated as you want. In its simplest form you attach data sources (such as a database with a JDBC connection) and you structure your joins and layout fields onto a form. You can even tie it into a Java EE container if needed.
There are examples on their website and it has a rather large community to help with questions.

What tool for printing Invoices and similar documents in Java Swing?

I'm looking for a good tool for printing Invoices, Receipts and similar documents in Java Swing. I have tried JasperReports but it is pretty hard to get a dynamic layout and it is designing for reports.
A requirement that I have is that the document should be sent directly to the printer and must not be saved to a file. So some tools that first creates an Office Document or a PDF document isn't a solution for me.
Any recommendations?
You might want to give Docmosis a go. You can create dynamic documents in various formats with the advantage that layout is specified in a template (being a simple doc or odt file) and content can be dynamically managed based on data. The type of layout your link refers to is pretty easy to achieve by using Docmosis conditional fields or by adjusting your input data.
In terms of printing only, Docmosis lets you stream the resulting output document anywhere. You could stream it to code that will send it to a printer directly.
I recommend to use DynamicReports, an open source and based on JasperReports.
You can send report directly to the printer.
Printing in Java revolves around a fairly simple but powerful API that provides you with a canvas. Fromthere you can easily paint any information using the Java2D API in the same way you would override a paintComponent() function.

Optimized graph drawing for the web

Having seen some suggestions for graphs, I wonder what's the optimum for my problem.
I want to render a directed graph to a servlet/picture that is displayed in the browser. There should be some kind of optimization of position. No dependency to Swing would be preferred. Algorithms are not important, since the structure of the graph is determined by business logic. It would be desired to be able add labels to edges as well.
it would be optimal if i can serve this as png/svg.
Which library/service would you recommend?
clarifications:
1) The question is all about Graphs - like Directed Acyclic Graph - NOT - Charts.
2) flot, Google Charts - cannot plot graphs, only charts, or have i missed something?
3) no i do not need interactivity
4) graphviz would be nice, but the grappa java library is quite outdated and is built upon swing/awt. while it may be theoretically possible to render swing to images, it would not be my favorite way to to so in a server-app.
5) it would be fine to use an online service where the images are not hosted locally.
edit: added links to Wikipedia to clarify graph/chart term
Take a look at graphviz
yFiles might be useful for this.
How about the dot component of Graphviz? It produces graphs (not charts), outputs to PNG and SVG, and supports labeling edges. You can shell out to dot to generate the image you need, and return an img tag that references that. Alternatively, you can return an img tag that references a URL that will generate the requisite graph (or retrieve a cached copy). Here's the dot info:
http://www.graphviz.org/pdf/dotguide.pdf
You might also take a look at WebDot, which is apparently designed for this purpose:
http://www.graphviz.org/webdot/
As well as waiting weeks to hear about the Magic Framework that's going to solve all your problems in one line of code, there is also the other option of just Writing Some Code yourself to do exactly what you want... (I'm not saying it's 10 minutes' work, but it's probably one or two days, and you posted your question over two weeks ago...)
Have you had a look, for example, at the Wikipedia entry on Force-based algorithms-- it has pseudocode and a few links that might be helpful.
I'm assuming it is the layout algorithm that's the issue, and not the matter of creating a BufferedImage, drawing to its graphics context, PNG-encoding it and sending it down the socket. You really don't need a framework for that bit, I don't think.
Try aiSee. It is used by all kinds of web-based applications for data mining, static program analysis, matrix visualization, network analysis, and whatnot. It is also used by some MediaWikis as their graph-layout backend.
They have a huge database of sample graphs over at aiSee.com. Check it out. It supports edge labels, export to mapped SVG and HTML, and is not dependent on Swing.
We create mxGraph for such requirements. We did actually release it in 2006, but took a while to notice this question...
For serverside, try JUNG, you can run it against Batik and produce beautiful SVG or PNG files. JUNG has a nice design and very powerful layout algorithms...
Also, since you mention that "it would be fine to use an online service", graphviz provide a service called webdot to render graphs.
There are others along this line as well... e.g. http://graph.gafol.net/ (seems to be down)
Client side:
Try http://arborjs.org/ for a minimal(ish) library it is dedicated to layout, use this is you like to prefer your own rendering routines (div, canvas, svg, paper.js, processing... etc).
I also like http://sigmajs.org/ for a more complete approach, build in touch support, plugins, file formats, etc.
Interestingly, the Eclipse project has an SWT/JFace component/framework capable of displaying and generating (import/export) Graphviz's 'DOT' format, in pure Java:
ZEST (home page & download links)
See http://wiki.eclipse.org/Graphviz_DOT_as_a_DSL_for_Zest for usage examples.
Although ZEST is touted as an Eclipse plugin, it does seem that the DOT-manipulation API's can be used standalone and external to an Eclipse installation.
Cheers
Rich
You may try sigma.js: http://sigmajs.org/
It is a lightweight, open source library in Javascript to display large graphs on the Web.
JPGD is a Graphviz parser in Java. It's a little abandoned, but the code is nice and clear, and if you find bugs I'm sure the author would accept contributed fixes.
Although advertised as a parser, it is also a generator. You can build Graphs as collections of Node and Edge objects, then get .dot using Graph.toString(). Getting this as a graphic would be a simple shell out to the Graphviz dot executable.
Alternatively, dot is very easy to generate yourself. In the simplest case, it's just a matter of writing a potted header
digraph myGraph {
... followed by one edge definition per edge
node1 -> node2 ;
... followed by a closing brace
}
so i took alook at all the given answers and links, it looks like Prefuse/Flare will by the optimal choice.
they have very appealing visialisations, plus they have built in support for graphs.
Maybe check out Google Charts?
You can use SVG in combination with Batik. I have used this several times for displaying graphics. Batik with Java 1.5 is very fast. With this solution you can program your graph in Java with no dependency on Swing. You can add labels where you want, host it as a Servlet and display it as png or svg.
You can create the graphs in SVG (this is an XML document).
You use Batik to transform the SVG-document to a PNG/JPG image.
You can use a Servlet to stream this image back to the browser.
In java you build an SVG(=XML) document. Samples for SVG graphs can be found here:
Directed graph and here: Simple directed graph
See this question, especially Stephan's answer about prefuse. I read that you do not need interactivity, but prefuse still may be useful.
I can whole-heartedly recommend flot - excellent!
See examples here.
JFreeChart might be the way you want to go, but you make a distinction between Charts and Graphs. Maybe you can explain what you mean by that. I've usually used these terms synonymously. :)
JFreeChart has good scatter, bar and line graphs as well as fun ones like Pie and Dial so maybe it will work for you.

Categories