failed to looping dataset in 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;
}

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

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

==== edit again ====

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);


    }

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..?

Answers


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.


Need Your Help

knotckout js foreach appending rows automatically in IE 7 and 8

javascript internet-explorer-8 internet-explorer-7 knockout.js

I have a "mini-cart" in a eCommerce site that I am bulding. For the "mini-cart" i use foreach to add items to a table.

Plot with margin text that scales for multiple plots?

r plot

I've created a figure with two y-axes, and use mtext() to label the right-hand axis.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.