Getting Java- and Javascript-generated charts to look similar - java

I'm having the following scenario: I'm displaying charts in the client side using the Javascript chart library Raphael. On clicking download I need to generate the same chart into pdf and display it to the user. I'm using JFreeChart to create charts on the server side. The problem is that since I'm using two different chart libraries, both look different. What is the solution for this?
The chart should be free for commercial use.

4 options here :
Use Google Chart. http://code.google.com/apis/chart/
JQuery Chart. http://www.1stwebdesigner.com/css/top-jquery-chart-libraries-interactive-charts/
Create Applet, use your JFreeChart and put it on the applet. Then provide the data from javascript to the applet. (If you really insist to make a very similar UI)
On the servlet convert your chart to image, and store it in session. Later on, in your JSP, get the image from the session. check this link for the details. But this one won't exactly the same as option no 3.

Related

Generate a png or jpeg image of a webpage using some java jar

I have a Java EE application running and on one of its webpage, I want to add a functionality that whenever the user presses a certain button, I get an image of ONLY the webpage which is currently displayed on the user end.
I have tried using a library for the purpose http://code.google.com/p/java-html2image/wiki/HtmlImageGenerator
My code using the above library is:
HtmlImageGenerator imageGenerator = new HtmlImageGenerator();
imageGenerator.loadUrl("http://localhost:8080/scheduler/xxx")
imageGenerator.getLinks();
imageGenerator.saveAsImage("sos.png");
It does generate an image but my page contains a lot of css and colors but the image which is generated does not seem to add that color and infact produces a blue screen with almost no css applied.
Can someone help in the code or suggest any alternative libraries for the same?
How about using jQuery or java script, on googling a bit I found the following two existing posts in stackoverflow
generating a screenshot of a website using jquery
Take a screenshot of a webpage with JavaScript?

Plot Graph In web application

I am developing a web application using Spring. I need to plot graphs and display them to the user. The values are stored in a database. How do I achieve this?
You have to decide where do you want to create the charts. You have two options:
Creating the chart on the server and send them to the client as image or pdf.
Sending raw data to the client and let them render the charts via html, flash or javascript
Each way has its own advantages and limitations - you have to decide for your specific use case.
If you render the charts on server side you are limited regarding interactivity but you clients don't need much performance to render the charts. Here you have to think about caching to protect your server performance.
On the client side you have to deal with diffent browsers and must think about the client render performance.
If 2. is ok for you, I would recommend using javascript - so your users don't need to install any plugins like flash and you have a lot of possibilites to create nice charts.
There are some nice frameworks to create charts using javascript, for example:
HighCharts
gRaphaƫl
JS Charts
...
I have used Google Charts with Spring MVC before. Normally whenever I have needed to display chart, I have always displayed tabular data along side the chart as well. So, I just take jQuery, parse the html table for data and pass it to google Chart API. You may want to look at the Google Chart pages for examples. It is quite nice.
As #aiolos said, you can generate your chart image in the client or in the Server. I haven't work with JavaScript enabled charts, but when I have to generate charts the server-side way i'll go with Cewolf. It's a Java Library based of JFreeChart that has some useful tags to embed charts in JSP pages.
I tested it in Spring Applications and works like a charm.

Good format for vector graphics for generation in java and use/open/print in windows?

We have a java web application. The application generates a big image with company structure diagramm on it as jpeg. Users download the image and want to print it on DIN A2 (big paper format). The jpeg in this scale has pretty bad quality after printing.
Our idea is to generate an image in vector graphics. What vector graphics format suits the best our needs, considering that we code in java and the users have windows and use MS IE browser?
May be there is a better way archieve this? Like let the browser to display the image and let users to print the page?
PDF has been invented exactly for the same purpose. iText library enables you to draw lines, boxes, circles and insert whatever text you like. If you want to automate it a bit using templates there's JasperReports which utilizes iText.
A well known vector graphics format is Scalable Vector Graphics. It's basically an XML file (starting with <svg> tag. It can be viewed in browsers like Firefox without additional plugins.
For java, you can use the Java 2D API to create SVG format. A tutorial can be found here:
If you need the vector graphic for IE you need VML, similar to SVG but can be rendered by Internet Explorer.
RaphaelJS can be used for vector graphics independent of browser model but it's client side and you may not want to do client side processing on every page load.

java - producing charts in PDF form

I'm looking for suggestions on the easiest way to create charts and have them printed out as PDFs. This has to be done in Java.
I was looking at something like: http://jcckit.sourceforge.net/index.html
But I don't see how to turn those charts into PDFs.
Any ideas?
Ireport is what you are looking for
If you want to control this process from Java, then you could use JFreeChart and Docmosis together to produce PDF reports that contain charts you generate on the fly. Otherwise you could look at something like Yellowfin to perform higher level reporting controlled and administered via a browser.

Library to render Directed Graphs (similar to graphviz) on Google App Engine

I am looking for a Java or Python library that can render graphs in the Dot language as image file. The problem is that I need a library that I can use on Google App Engine. Basically I am looking for a library that can convert the text description of a directed graph into an image of the graph.
For example:
Covert this edge list:
[A,B]
[B,C]
[A,C]
[C,D]
Into this image:
I used Graphviz for this example, but I know it is not possible for me to use it with Google App Engine.
Canviz is what you are looking for: it is a JavaScript library for drawing Graphviz graphs to a web browser canvas. It works with most browsers.
Using Canviz has advantages for your web application over generating and sending bitmapped images and imagemaps to the browser:
The server only needs to have Graphviz generate xdot text; this is faster than generating bitmapped images.
Only the xdot text needs to be transferred to the browser; this is smaller than binary image data, and, if the browser supports it (which most do), the text can be gzip- or bzip2-compressed.
The web browser performs the drawing, not the server; this reduces server load.
The user can resize the graph without needing to involve the server; this is faster than having the server draw and send the graph in a different size.
To see it in action, look here.
Google Charts API now supports GraphViz experimentally. (Note that the entire Image Charts project is officially deprecated.)
You could take a look at the flash based perfuse project if just need to display a graph and not having it embedded as an image is acceptable.
They have some example applications of the library such as this Dependency Graph.
I do not think there is such pure python library, the best you can do is use NetworkX, it can draw using matplotlib or pygraphviz. Maybe you can modify networkx's matplotlib code to draw on server side, here is the code
Another problem is google app engine doesn't have any drawing API, but you may simply use SVG to generate such graphs or may be google charts API have something already there.

Categories

Resources