geneticalgorithm2.LineChart_AWT.java Source code

Java tutorial

Introduction

Here is the source code for geneticalgorithm2.LineChart_AWT.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package geneticalgorithm2;

import java.util.ArrayList;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.ApplicationFrame;

/**
 *
 * @author Lenovo
 */
class LineChart_AWT extends ApplicationFrame {
    public LineChart_AWT(String applicationTitle, String chartTitle, ArrayList<Double> fitnessArrayList) {
        super(applicationTitle);
        JFreeChart lineChart = ChartFactory.createLineChart(chartTitle, "Number of Generations", "Minimum Value",
                createDataset(fitnessArrayList), PlotOrientation.VERTICAL, true, true, false);

        ChartPanel chartPanel = new ChartPanel(lineChart);
        chartPanel.setPreferredSize(new java.awt.Dimension(560, 367));
        setContentPane(chartPanel);
    }

    private DefaultCategoryDataset createDataset(ArrayList<Double> fitnessArrayList) {
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        for (int row = 0; row != fitnessArrayList.size(); row++) {
            dataset.addValue(fitnessArrayList.get(row), "minimum", String.valueOf(row + 1));
        }
        return dataset;
    }
}