使用Java Applet绘制图形 [英] Plotting a graph using Java Applet
问题描述
我有一个问题,我必须使用excel文件中的一些数据在applet上绘制图形。我需要设计一个小程序,可以在同一个小程序上显示图形和数据。
我很难用Java编写一些代码来编写一些CSVreader和ExcelReader文件。现在,我真的被困在如何获取这些数据并将其绘制在applet上。
我不知道使用哪个类/库来绘制图形,以及如何缩放它,绘制实际点或设计applet本身。如果有人能帮助我,我将不胜感激。
编辑
:
pre $ code> mis(t)nt Vt N(t)h(t)H(t)
1 141 200,000 200,000 0.00071 0.00071
2 103 200,000 199,859 0.00052 0.00122
此处绘制图表对于 mis(t)
与 h(t)
。
也许,您正在寻找的是Java中易于使用的Chart应用程序。答案是 jFreeChart 。他们有很多样本,以便立即开始使用。
关于读取CSV文件以将数据传递给jFreeChart,请使用 OpenCSV
读取CSV文件非常简单 -
CSVReader rec =新的CSVReader(新的FileReader(filePath));
String [] recLine; ((recLine = rec.readNext())!= null){
//从recLine获取数据
}
让我知道您是否需要更多细节。
I have a problem where I have to draw a graph on an applet using some data in an excel file. I would need to design an applet where I can display the graph and the data on the same applet.
I had a hard time writing some code in Java to code some CSVreader and ExcelReader files. Now, I am really stuck in how to take this data and graph it on an applet.
I don't know which class/libraries to use for drawing the graph and how to scale it and draw the actual points or designing the applet itself. I would appreciate if someone can help me out.
EDIT
Sample input:
mis(t) nt Vt N(t) h(t) H(t)
1 141 200,000 200,000 0.00071 0.00071
2 103 200,000 199,859 0.00052 0.00122
Here, the graph is to be plotted for mis(t)
vs. h(t)
.
Perhaps, what you are looking for is an easy to use Chart application in Java. The answer is jFreeChart. They have a lots of samples as well to get you started immediately.
And regarding reading CSV files to pass the data to jFreeChart, use OpenCSV
Reading a CSV file is as simple as -
CSVReader rec = new CSVReader(new FileReader(filePath));
String[] recLine;
while ((recLine = rec.readNext()) != null) {
//Get the data from recLine
}
Let me know if you need more details.
这篇关于使用Java Applet绘制图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!