用于创建图形的 Java 库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6557567/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java library to create graphs
提问by Keshan De Silva
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
什么是最好且易于使用的 Java 图形库?我正在使用 Swing 应用程序,需要为该项目集成一个图形
采纳答案by Andrew Thompson
One commonly used charting API is JFreeChart.
一种常用的图表 API 是JFreeChart。
回答by evilone
I answered in this thread, could be helpful Java graph library for dynamic visualisation
我在这个线程中回答,可能有助于动态可视化的 Java 图形库
回答by Prashant Bhate
Options
选项
If graphs you mean like clusters nodes and links visualization have a look at graphviz gallery
To generate charts see jfreechart demoDownload jfreechart jfreechart-1.0.13
- Use java advanced imaging - jai see histogram demo source
如果图形你的意思是像集群节点和链接可视化,请查看graphviz 库
- 使用java高级成像-jai查看 直方图演示源码
Steps to create a chart using jfreechart
使用 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
如果使用 Swing 应用程序ChartPanel
来渲染图表
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(...)
ChartUtilities.saveChartAsPNG(new File("histogram.PNG"), chart, width, height);