0

Ok, I am developing a java similiarity checker application between two or more java codes that used jfreechart to display the presentation. To get the data that I need, I use getter setter to accommodate the data.

Here is the getter setter code

 public class ReportChart {

    public ReportChart() {

    }

    private String nameOfMainFile;
    private String nameOfComparingFile;
    private double levensthein;
    private double jaccard;
    private double cosine;

    public double getLevensthein() {
        return levensthein;
    }

    public void setLevensthein(double levensthein) {
        this.levensthein = levensthein;
    }

    public double getJaccard() {
        return jaccard;
    }

    public void setJaccard(double jaccard) {
        this.jaccard = jaccard;
    }

    public double getCosine() {
        return cosine;
    }

    public void setCosine(double cosine) {
        this.cosine = cosine;
    }

    public String getNamaFileUtama() {
        return nameOfMainFile;
    }

    public void setNameOfMainFile(String namaFileUtama) {
        this.nameOfMainFile = namaFileUtama;
    }

    public String getNamaFilePembanding() {
        return nameOfComparingFile;
    }

    public void setNameOfComparingFile(String namaFilePembanding) {
        this.nameOfComparingFile = namaFilePembanding;
    }
}

To get the data, I write this source code below. You can see on the end of code, I am setting that will be implement the getter setter code.

public final class ASTParseUnit {
final IParserSelector parserSelector;

List<ReportChart> Data;
ReportChart detailChart;
String IDLexer;
/**
 * Constructor.
 *
 * @param parserSelector
 */
public ASTParseUnit(final IParserSelector parserSelector) {
    Data = new ArrayList <ReportChart>();
    this.parserSelector = parserSelector;
}


public ASTManager parse(final JCCDFile[] files) {

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

    StringBuilder namaFileUtama = 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();

        if (idLexerSeleksi != getIDLexer()) {

            nameOfMainFile.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 = namaFileUtama.toString();
    String resultOfLevenstheins = countLevenstheins.toString();
    String resultOfJaccards = countJaccards.toString();
    String resultOfCosines = countCosines.toString();


    detailChart = new ReportChart();
    detailChart.setNameOfMainFile(name);
    detailChart.setNameOfComparingFile(enemy);
    detailChart.setLevensthein(Double.parseDouble(resultOfLevenstheins));
    detailChart.setJaccard(Double.parseDouble(resultOfJaccards));
    detailChart.setCosine(Double.parseDouble(resultOfCosines));
    Data.add(detailChart);

    LayeredBarChart lyb = new LayeredBarChart("Presentase Kemirpan", Data);

    return container;
}

Now, time to get the setter in my jfreechart

public class LayeredBarChart extends ApplicationFrame {

List<ReportChart> theDatas;

public LayeredBarChart(String s, List<ReportChart> chartData) {
    super(s);

    this.theDatas = chartData;

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

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

private CategoryDataset createDataset() {


    final DefaultCategoryDataset dataset = new DefaultCategoryDataset();


    for (ReportChart reportChart : datanya) {

        dataset.addValue(reportChart.getLevensthein(), "Levensthein", reportChart.getNamaFilePembanding());
        dataset.addValue(reportChart.getJaccard(), "Jaccard", reportChart.getNamaFilePembanding());
        dataset.addValue(reportChart.getCosine(), "Cosine", reportChart.getNamaFilePembanding());


        System.out.println("");


    }

    return dataset;
}

from the end of the code above, I dont understand Why my for (object) it not looping in jfreechart ? I will describe the problem.

So, Assumpted that I am compare FileOne and FileTwo the it will give me a bar in my chart. Now Time to FileOne and FileThree.

Now The problem is rise, jfreechart not create two bars. But when I debugging in code, FileOne and FIleThree still compared. It has.

NOw, The chart is created but it gives just a bar, that is the last compared file a.k.a is FileThree.

Where am I lost in this code ?

Any solution it so appreciated..

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

this is the createChart method.

 private static JFreeChart createChart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createBarChart("Similiarity Percentage", "Compared File", "Main File", categorydataset, PlotOrientation.VERTICAL, 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;
}

but When I just input manual data like

dataset.addValue(90D, s, s3);
dataset.addValue(20, s1, s3);
dataset.addValue(32, s2, s3);

dataset.addValue(40D, s, s4);
dataset.addValue(69, s1, s4);
dataset.addValue(87, s2, s4);

dataset.addValue(51, s, s5);
dataset.addValue(90, s1, s5);
dataset.addValue(8, s2, s5);

it just work. But why from the looping it is failed?. Btw Thanks again, I am so appreciated of you...

edit

datanya is the indoneisan language that means the datas. I am confuse, because when I write like this

public CategoryDataset createDataset() {

DefaultCategoryDataset dataset = new DefaultCategoryDataset();

for (ReportChart reportChart : datanya) {


  System.out.print("Looping : " + a + "     =>     ["
    + reportChart.getLevensthein() + " "
    + reportChart.getNameMainFile() + " "
    + reportChart.getNameFileCompare() + " ] ");

  System.out.print("  [" + reportChart.getJaccard() + " "
    + reportChart.getNameMainFile() + " "
    + reportChart.getNameFileCompare() + " ] ");

  System.out.print("  [" + reportChart.getCosine() + " "
    + reportChart.getNameMainFile() + " "
    + reportChart.getNameFileCompare() + " ]     ");

    System.out.println("=============================================");

    }

    return dataset;
}

it works. perhaps i need a condition, if what then what ? thnk you for the help...

user3767455
  • 29
  • 3
  • 8
  • 1
    I don't see any obvious problems in the code. Can you show your `createChart` method? – Erwin Bolwidt Jun 28 '14 at 05:22
  • 1
    To explain why the `for( ReportChart reportChart : datanya)` doesn't add anything to the `CategoryDataset` one will have to study declaration and use of `datanya`, which doesn't occur anywhere else in the code you have presented. – laune Jun 28 '14 at 09:26
  • You asked this question twice, and I answered the other one. http://stackoverflow.com/questions/24470026/failed-to-looping-dataset-in-jfreechart – David Gilbert Jun 29 '14 at 06:15

0 Answers0