gpt4 book ai didi

java - 将表上的数据显示到 jfreechart 中

转载 作者:行者123 更新时间:2023-12-01 12:48:28 25 4
gpt4 key购买 nike

我正在构建一个应用程序来检查两个或多个 java 代码之间的相似性。现在,我有一个数据存储在表中。构建此表的代码如下

public final class ASTParseUnit {

String IDLexer;

public ASTParseUnit(final IParserSelector parserSelector) {
this.parserSelector = parserSelector;
}

public String getIDLexer() {
return IDLexer;
}

public void setIDLexer(String iDLexer) {
IDLexer = iDLexer;
}

public ASTManager parse(final JCCDFile[] files) {

final ASTManager container = new ASTManager(
TipeNode.PROJECT.getTipe(), null);


JCCDFile temp;
temp = files[0];
String name = temp.getName();
String idLexerSeleksi = "";

StringBuilder nameOfFileMainFile = new StringBuilder();

StringBuilder countLevenstheins = new StringBuilder();
StringBuilder countJaccards = new StringBuilder();
StringBuilder countCosines = new StringBuilder();


for (final JCCDFile file : files) {
container.tandaiNodeRoot();

parseTree(file, container);
if (name.equals(file.getName())) {
idLexerSeleksi = getIDLexer();
}

LevenshteinDistance lv = new LevenshteinDistance();
SimilarityRunner sr = new SimilarityRunner(); // my class to count similiarity

if (idLexerSeleksi != getIDLexer()) {

nameOfFileMainFile.append(file.getName());
System.out.println(temp.getName() + " ==> " + file.getName());



countLevenstheins.append(lv.printDistance(idLexerSeleksi, getIDLexer()));
countJaccards.append(sr.hitungJaccard(idLexerSeleksi, getIDLexer()));
countCosines.append(sr.hitungCosine(idLexerSeleksi, getIDLexer()));

}
}

String enemy = nameOfMainFile.toString();
String resultOfLevenstheins = countLevenstheins.toString();
String resultOfJaccards = countJaccards.toString();
String resultOfCosines = countCosines.toString();

DefaultTableModel model = (DefaultTableModel) Main_Menu.jTable3.getModel();
List<Report3> theListData = new ArrayList<Report3>();
Report3 persentaseTabel = new Report3();

persentaseTabel.setMainFile(name);
persentaseTabel.setComparingFile(enemy);
persentaseTabel.setLevenstheins(resultOfLevenstheins);
persentaseTabel.setJaccard(resultOfJaccards);
persentaseTabel.setCosine(resultOfCosines);

theListData.add(persentaseTabel);
for (Report3 report3 : theListData) {
model.addRow(new Object[]{
report3.getMainFile(),
report3.getComparingFile(),
report3.getLevenstheins(),
report3.getJaccard(),
report3.getCosine(),});
}

return container;
}

现在,我如何将该表表示为 jfreeChart ?这是我的 jfreechart 代码...

public class LayeredBarChartDemo11 extends ApplicationFrame {

public LayeredBarChartDemo11(String s) {
super(s);


CategoryDataset dataset = createDataset();
JFreeChart chart = createChart(dataset);
ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
setContentPane(chartPanel);
chartPanel.setMouseWheelEnabled(true);

//Main_menu is my form
Main_Menu.presentase.removeAll();
Main_Menu.presentase.setLayout(new java.awt.BorderLayout());
Main_Menu.presentase.add(chartPanel);
}

private static CategoryDataset createDataset() {
String s = "Levensthein";
String s1 = "Jaccard";
String s2 = "Cosine";
String s3 = "a.java";
String s4 = "b.java";
String s5 = "c.java";

DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset();
defaultcategorydataset.addValue(100D, s, s3);
defaultcategorydataset.addValue(20, s1, s3);

defaultcategorydataset.addValue(40D, s, s4);
defaultcategorydataset.addValue(170, s, s5);
defaultcategorydataset.addValue(69, s1, s4);
defaultcategorydataset.addValue(51, s1, s5);
defaultcategorydataset.addValue(32, s2, s3);
defaultcategorydataset.addValue(87, s2, s4);
defaultcategorydataset.addValue(68, s2, s5);
defaultcategorydataset.addValue(89, s2, s4);
defaultcategorydataset.addValue(8, s2, s5);
return defaultcategorydataset;
}

private static JFreeChart createChart(CategoryDataset categorydataset) {
JFreeChart jfreechart = ChartFactory.createBarChart("Persentase Kemiripan", "File Pembanding", "File Utama", categorydataset, PlotOrientation.HORIZONTAL, true, true, false);
CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
categoryplot.setDomainGridlinesVisible(true);
categoryplot.setRangePannable(true);
categoryplot.setRangeZeroBaselineVisible(true);
categoryplot.configureRangeAxes();
NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
LayeredBarRenderer layeredbarrenderer = new LayeredBarRenderer();
layeredbarrenderer.setDrawBarOutline(false);
categoryplot.setRenderer(layeredbarrenderer);
categoryplot.setRowRenderingOrder(SortOrder.DESCENDING);
GradientPaint gradientpaint = new GradientPaint(0.0F, 0.0F, Color.blue, 0.0F, 0.0F, new Color(0, 0, 64));
GradientPaint gradientpaint1 = new GradientPaint(0.0F, 0.0F, Color.green, 0.0F, 0.0F, new Color(0, 64, 0));
GradientPaint gradientpaint2 = new GradientPaint(0.0F, 0.0F, Color.red, 0.0F, 0.0F, new Color(64, 0, 0));
layeredbarrenderer.setSeriesPaint(0, gradientpaint);
layeredbarrenderer.setSeriesPaint(1, gradientpaint1);
layeredbarrenderer.setSeriesPaint(2, gradientpaint2);
return jfreechart;
}

public static JPanel createDemoPanel() {
JFreeChart jfreechart = createChart(createDataset());
ChartPanel chartpanel = new ChartPanel(jfreechart);
chartpanel.setMouseWheelEnabled(true);
return chartpanel;
}

这是我的应用程序的屏幕截图 https://www.dropbox.com/s/opmao5l9sy0df8v/New%20Picture%20%2810%29.png

最佳答案

假设您希望图表反射(reflect)(可能更改的)表条目,请添加 TableModelListener到您的TableModel。根据收到的TableModelEvent,相应地更新CategoryDataset;收听图表将根据响应自行更新。

如果在评估查询和比较函数后表模型没有改变,请使用JDBCCategoryDataset,提到here ,查询数据库;然后构造相应的表模型。

关于java - 将表上的数据显示到 jfreechart 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24454660/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com