无法在jfreechart中循环数据集 [英] failed to looping dataset in jfreechart

查看:69
本文介绍了无法在jfreechart中循环数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以在jfreechart?中创建循环数据集.我有一个包含数据的列表. 这是代码

It is possible to create a loop dataset in jfreechart ?. I have a List that contains data. Here is the code

List<ReportChart> theDatas;
public CategoryDataset createDataset() {

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    for (ReportChart reportChart : theDatas) {                      
        dataset.setValue(reportChart.getLevensthein(), reportChart.getMainFileName(), reportChart.getComparingFileName());
        dataset.setValue(reportChart.getJaccard(), reportChart.getMainFileName(), reportChart.getComparingFileName());
        dataset.setValue(reportChart.getCosine(), reportChart.getMainFileName(), reportChart.getComparingFileName());


    }
    return dataset;
}

在上面的代码中,我刚刚从列表中获取了最后一个数据? 非常感谢您的帮助...

In code above, I just get the last data from my List ? It so appreciated for the help...

edit =============

我尝试了一些更改,但是我不知道如何解决此问题.

I try some changes, but I dont know how to get this solved.

public CategoryDataset createDataset() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    for (ReportChart reportChart : theDatas) {

        final String nameOfMainFile = reportChart.getMainFileName();
        final String nameOfComparingFile = reportChart.getComparingFileName();
        final double scoreOfLevenstheins = reportChart.getLevensthein();
        final double scoreOfJaccard = reportChart.getJaccard();
        final double scoreOfCosine = reportChart.getCosine();
        final String algoritma1 = "Levenstheins";
        final String algoritma2 = "Jaccard";
        final String algoritma3 = "Cosine";

        System.out.println(algoritma1 + " : " + "<" + nameOfMainFile + " || " + nameOfComparingFile + ">" + " : " + scoreOfLevenstheins);
        System.out.println(algoritma2 + "      : " + "<" + nameOfMainFile + " || " + nameOfComparingFile + ">" + " : " + scoreOfJaccard);
        System.out.println(algoritma3 + "       : " + "<" + nameOfMainFile + " || " + nameOfComparingFile + ">" + " : " + scoreOfCosine);

        dataset.addValue(scoreOfLevenstheins, algoritma1, nameOfComparingFile);
        dataset.addValue(scoreOfJaccard, algoritma2, nameOfComparingFile);
        dataset.addValue(scoreOfCosine, algoritma3, nameOfComparingFile);

    }

    return dataset;
}

这是我选择数据时应用程序的第一个屏幕截图: https: //www.dropbox.com/s/t46mzo42of7hdyl/failed1.png ,这是代表两个代码相似的图形 https://www.dropbox.com/s/a5dpzf9j22tfqdh/failed2.png

This is the first screenshot of my application when I am choose the data : https://www.dropbox.com/s/t46mzo42of7hdyl/failed1.png and this is the graph to represented the similiar of both code https://www.dropbox.com/s/a5dpzf9j22tfqdh/failed2.png

.TrashGod先生.这是一个完整的问题... 无法在JfreeChart中循环数据列表

Mr .TrashGod. this is the complete problem ... failed to loop List of Data in JfreeChart

==== edit again ====

我一直在尝试新的实验,dataset.addvalue在可比较的列键中需要唯一的ID和值. 像这样的代码:

I ve been try new experiment, dataset.addvalue need unique ID and value in comparable column key. the code like this :

DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset();

    for (ReportChart object : theDatas) {
        String algoritma1 = "Levenstheins";
        String algoritma2 = "Jaccard";
        String algoritma3 = "Cosine";
        String nameOfComparingFile = object.getComparingFileName();
        double scoreLv = object.getLevensthein();
        double scoreJc = object.getJaccard();
        double scoreCo = object.getCosine();


        defaultcategorydataset.addValue(scoreLv, algoritma1, nameOfComparingFile);
        defaultcategorydataset.addValue(scoreJc, algoritma2, nameOfComparingFile);
        defaultcategorydataset.addValue(scoreCo, algoritma3, nameOfComparingFile);

        String s = "First";
        String s1 = "Second";
        String s2 = "Third";
        String s3 = "Category 1";
        String s4 = "Category 2";
        String s5 = "Category 3";
        String s6 = "Category 4";
        String s7 = "Category 5";

        defaultcategorydataset.addValue(scoreLv, algoritma1, s3);
        defaultcategorydataset.addValue(scoreJc, algoritma2, s4);
        defaultcategorydataset.addValue(scoreCo, algoritma3, s5);
        defaultcategorydataset.addValue(scoreLv, algoritma1, s6);
        defaultcategorydataset.addValue(scoreJc, algoritma2, s7);
        defaultcategorydataset.addValue(scoreCo, algoritma3, s3);
        defaultcategorydataset.addValue(scoreLv, algoritma1, s4);
        defaultcategorydataset.addValue(scoreJc, algoritma2, s5);
        defaultcategorydataset.addValue(scoreCo, algoritma3, s6);
        defaultcategorydataset.addValue(scoreLv, algoritma1, s7);
        defaultcategorydataset.addValue(scoreJc, algoritma2, s3);
        defaultcategorydataset.addValue(scoreCo, algoritma3, s4);
        defaultcategorydataset.addValue(scoreLv, algoritma1, s5);
        defaultcategorydataset.addValue(scoreJc, algoritma2, s6);
        defaultcategorydataset.addValue(scoreCo, algoritma3, s7);


    }

由此,我知道我需要一个可比的.如何使这个真正的Mr.trashGod.我在您指向我的链接中尝试了此代码

from that, I know that I need a comparable. How to make this real Mr.trashGod. i was try this code from the link that you pointing to me

public class UniqueValue implements  Comparable<UniqueValue>{

private final String uniqueId;
private final String value;

public UniqueValue(String uniqueId, String value) {
    this.uniqueId = uniqueId;
    this.value = value;
}

UniqueValue(String nameOfComparingFile, double scoreLv) {
    throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}


@Override
public int compareTo(UniqueValue o) {
    return uniqueId.compareTo(o.uniqueId);
}

@Override
 public int hashCode() {
    return uniqueId.hashCode();
}

@Override
 public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }
    if (obj instanceof UniqueValue) {
        return uniqueId.equals(((UniqueValue)obj).uniqueId);
    }
    return false;
}

  @Override
public String toString() {
        return value;
    }

}

现在,如何使用此类..​​

and now, how to use this class..?

推荐答案

看看

Take a look at the API docs for the setValue() method - the first argument is the data value, followed by the row and column keys that identify the cell for the value. So in your code you are setting the value in one cell three times in each iteration of the loop. You'll end up with the value you set the third time.

这篇关于无法在jfreechart中循环数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆