16

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

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Keshan De Silva
  • 839
  • 1
  • 11
  • 25

3 Answers3

14

Options

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);
Prashant Bhate
  • 10,907
  • 7
  • 47
  • 82
9

One commonly used charting API is JFreeChart.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
5

I answered in this thread, could be helpful Java graph library for dynamic visualisation

Community
  • 1
  • 1
evilone
  • 22,410
  • 7
  • 80
  • 107