Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java library to create graphs [closed]

What is best and easy to use library for Java graphs? I am working with Swing application and need to integrate a graph for that project

like image 356
Keshan De Silva Avatar asked Jul 02 '11 14:07

Keshan De Silva


1 Answers

Options

  • If graphs you mean like clusters nodes and links visualization have a look at graphviz gallery

  • To generate charts see jfreechart demo Download jfreechart jfreechart-1.0.13

  • Use java advanced imaging - jai see histogram demo source

Steps to create a chart using jfreechart

Create Dataset and pass array of data

HistogramDataset dataset = new HistogramDataset();
dataset.addSeries("series label",arrayOfValues,noOfBins);

Create a chart object

JFreeChart chart = ChartFactory.
createHistogram( "plotTitle", "xaxis label", "yaxis label", 
                dataset, PlotOrientation.VERTICAL, false, false, false);

If swing application use ChartPanel to render chart

ChartPanel chartPanel = new ChartPanel(chart)
chartPanel.setPreferredSize(new java.awt.Dimension JavaDoc(500, 270));
chartPanel.setMouseZoomable(true, false);

If need to write chart to a file/stream use ChartUtilities.saveChartAsPNG(...)

ChartUtilities.saveChartAsPNG(new File("histogram.PNG"), chart, width, height);
like image 63
Prashant Bhate Avatar answered Sep 18 '22 15:09

Prashant Bhate