Example usage for org.jfree.chart ChartFrame setVisible

List of usage examples for org.jfree.chart ChartFrame setVisible

Introduction

In this page you can find the example usage for org.jfree.chart ChartFrame setVisible.

Prototype

public void setVisible(boolean b) 

Source Link

Document

Shows or hides this Window depending on the value of parameter b .

Usage

From source file:local.Statistics.LessSellCars.java

/**
 * @param args the command line arguments
 *///from w  w  w .ja  va  2s . co m
public static void carrosMenosVendidos() {
    Graficas_DAO gr = new Graficas_DAO();
    ResultSet rs = gr.getgraficaautomas();
    try {
        String nameAuto;
        int quantitySales;
        DefaultPieDataset data = new DefaultPieDataset();
        while (rs.next()) {
            nameAuto = rs.getString(3);
            quantitySales = rs.getInt(1);
            data.setValue(nameAuto, quantitySales);
        }
        JFreeChart chart = ChartFactory.createPieChart("GRAFICAS AUTOS MENOS VENDIDOS", data, true, true,
                false);
        ChartFrame frame = new ChartFrame("Autos menos vendidos", chart);
        frame.pack();
        frame.setVisible(true);
        rs.close();
        gr.close();
    } catch (SQLException ex) {
        Logger.getLogger(LessSellCars.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:local.Statistics.LessSellRepuesto.java

/**
 * @param args the command line arguments
 */// w  w w  .j av  a2  s  .com
public static void repuestosMenosVendidos() {
    Graficas_DAO gr = new Graficas_DAO();
    //obtencion de datos
    ResultSet rs = gr.getgraficarepuestomen();
    try {
        String nameAuto;
        int quantitySales;
        DefaultPieDataset data = new DefaultPieDataset();
        while (rs.next()) {
            nameAuto = rs.getString(3);
            quantitySales = rs.getInt(1);
            data.setValue(nameAuto, quantitySales);
        }
        JFreeChart chart = ChartFactory.createPieChart("GRAFICAS REPUESTO MENOS VENDIDOS", data, true, true,
                false);
        ChartFrame frame = new ChartFrame("Repuestos menos vendidos", chart);
        frame.pack();
        frame.setVisible(true);
        rs.close();
        gr.close();
    } catch (SQLException ex) {
        Logger.getLogger(LessSellRepuesto.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:local.Statistics.MostSellCars.java

/**
 * @param args the command line arguments
 *//*from   ww w.j  a v  a  2  s  .  c om*/
public static void carrosMasVendidos() {
    Graficas_DAO gr = new Graficas_DAO();
    //obtencion de datos
    ResultSet rs = gr.getgraficaautomas();

    try {
        String nameAuto;
        int quantitySales;
        Object[] fila = new Object[3];
        DefaultPieDataset data = new DefaultPieDataset();
        while (rs.next()) {

            nameAuto = rs.getString(3);
            quantitySales = rs.getInt(1);
            data.setValue(nameAuto, quantitySales);
        }
        JFreeChart chart = ChartFactory.createPieChart("GRAFICAS AUTOS MAS VENDIDOS", data, true, true, false);
        ChartFrame frame = new ChartFrame("Autos mas vendidos", chart);
        frame.pack();
        frame.setVisible(true);

        rs.close();
        gr.close();
    } catch (SQLException ex) {
        Logger.getLogger(MostSellCars.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:graph.jfreecharts.GraphFunction.java

/**
 * Plots an xyerror graph using jfreecharts
 * @param title the title of the graph// ww  w .  j a v a2  s . c om
 * @param xlabel the x axis title
 * @param ylabel the y axis title
 * @param legend the legend
 * @param data the data values
 */
protected static void plotData(String title, String xlabel, String ylabel, String[] legend, double[][][] data) {

    DefaultIntervalXYDataset xydata = new DefaultIntervalXYDataset();

    for (int i = 0; i < legend.length; i++) {
        xydata.addSeries(legend[i], data[i]);
    }
    // create a chart...
    JFreeChart chart = GraphFunction.createXYIntervalChart(title, xlabel, ylabel, xydata,
            PlotOrientation.VERTICAL, true, true, false);
    // create and display a frame...
    ChartFrame frame = new ChartFrame("First", chart);
    frame.pack();
    frame.setVisible(true);
    frame.setDefaultCloseOperation(javax.swing.JFrame.DISPOSE_ON_CLOSE);
}

From source file:view.visualization.TXTVisualization.java

public static void drawChart(String a, String b, String txt) {
    String[] boje = null;/* www. j a v a2  s  .  c  o m*/
    LinkedList<String> atributi = new LinkedList<String>();
    LinkedList<String> sviAtributi = new LinkedList<String>();
    String[] vrAtribut = null;
    XYSeries[] xy = null;
    XYSeriesCollection xySeriesCollection = new XYSeriesCollection();
    int brojac = 0;
    boolean kraj = false;
    LinkedList<Integer> numeric = new LinkedList<Integer>();

    try {
        BufferedReader in = new BufferedReader(new FileReader(txt));
        int br = Integer.parseInt(in.readLine().split(" ")[1]);
        for (int j = 0; j < br + 1; j++) {

            String pom = in.readLine();
            if (pom.contains("@attribute")) {
                if (pom.contains("numeric")) {
                    sviAtributi.add(pom.substring(11, pom.lastIndexOf("n") - 1));
                } else {
                    sviAtributi.add(pom.split(" ")[1]);
                }
            }
            if (pom.contains("@attribute") && pom.contains("numeric")) {
                atributi.add(pom.substring(11, pom.lastIndexOf("n") - 1));
            }
            if (!pom.contains("numeric")) {
                brojac++;
                numeric.add(j - 2);
            }

        }
        String s = in.readLine();
        boje = s.substring(s.indexOf("{") + 1, s.lastIndexOf("}")).split(",");
        xy = new XYSeries[boje.length];
        for (int i = 0; i < boje.length; i++) {

            xy[i] = new XYSeries(boje[i]);

        }
        while (!kraj) {
            String pom2 = in.readLine();

            if (!(pom2.contains("@data"))) {
                vrAtribut = pom2.split(",");
                for (int i = 0; i < xy.length; i++) {
                    if (xy[i].getKey().equals(vrAtribut[vrAtribut.length - 1])) {

                        xy[i].add(Double.parseDouble(vrAtribut[sviAtributi.indexOf(a)]),
                                Double.parseDouble(vrAtribut[sviAtributi.indexOf(b)]));

                    }
                }
            }
        }
        in.close();
    } catch (Exception e) {
        e.getMessage();
    }
    for (int i = 0; i < xy.length; i++) {
        xySeriesCollection.addSeries(xy[i]);
    }

    JFreeChart grafik = ChartFactory.createScatterPlot("Vizuelizacija", a, b, xySeriesCollection,
            PlotOrientation.VERTICAL, true, true, false);
    ChartFrame proba = new ChartFrame("DataMiner", grafik);

    proba.setVisible(true);
    proba.setSize(500, 600);

}

From source file:PerformanceGraph.java

/**
 * Plots the performance graph of the best fitness value so far versus the
 * number of function calls (NFC).//from ww w .j  a v  a2 s .c  o  m
 * 
 * @param bestFitness A linked hashmap mapping the NFC to the best fitness value
 * found so far.
 * @param fitnessFunction The name of the fitness function, used for the title and the
 * name of the file that is saved, e.g. "De Jong".
 */
public static void plot(LinkedHashMap<Integer, Double> bestFitness, String fitnessFunction) {
    /* Create an XYSeries plot */
    XYSeries series = new XYSeries("Best Fitness Value Vs. Number of Function Calls");

    /* Add the NFC and best fitness value data to the series */
    for (Integer NFC : bestFitness.keySet()) {
        /* Jfreechart crashes if double values are too large! */
        if (bestFitness.get(NFC) <= 10E12) {
            series.add(NFC.doubleValue(), bestFitness.get(NFC).doubleValue());
        }
    }

    /* Add the x,y series data to the dataset */
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(series);

    /* Plot the data as an X,Y line chart */
    JFreeChart chart = ChartFactory.createXYLineChart("Best Fitness Value Vs. Number of Function Calls",
            "Number of Function Calls (NFC)", "Best Fitness Value", dataset, PlotOrientation.VERTICAL, false,
            true, false);

    /* Configure the chart settings such as anti-aliasing, background colour */
    chart.setAntiAlias(true);

    XYPlot plot = chart.getXYPlot();

    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.black);
    plot.setDomainGridlinePaint(Color.black);

    /* Set the domain range from 0 to NFC */
    NumberAxis domain = (NumberAxis) plot.getDomainAxis();
    domain.setRange(0.0, ControlVariables.MAX_FUNCTION_CALLS.doubleValue());

    /* Logarithmic range axis */
    plot.setRangeAxis(new LogAxis());

    /* Set the thickness and colour of the lines */
    XYItemRenderer renderer = plot.getRenderer();
    BasicStroke thickLine = new BasicStroke(3.0f);
    renderer.setSeriesStroke(0, thickLine);
    renderer.setPaint(Color.BLACK);

    /* Display the plot in a JFrame */
    ChartFrame frame = new ChartFrame(fitnessFunction + " Best Fitness Value", chart);
    frame.setVisible(true);
    frame.setSize(1000, 600);

    /* Save the plot as an image named after fitness function
    try
    {
       ChartUtilities.saveChartAsJPEG(new File("plots/" + fitnessFunction + ".jpg"), chart, 1600, 900);
    }
    catch (IOException e)
    {
       e.printStackTrace();
    }*/
}

From source file:jfreechart.ViewGirlsBoysAvgChart.java

public static void viweGirlsAvgChart(List<String> testId, ArrayList<Double> totAvg, ArrayList<Double> girlsAvg,
        ArrayList<Double> boysAvg) throws SQLException, ClassNotFoundException {
    try {/* ww w.j  a v a 2 s . c o m*/
        UIManager.setLookAndFeel(new McWinLookAndFeel());
    } catch (UnsupportedLookAndFeelException ex) {
        Logger.getLogger(ViewEachStudentChart.class.getName()).log(Level.SEVERE, null, ex);
    }
    DefaultCategoryDataset objDataset = new DefaultCategoryDataset();

    for (Double marks : totAvg) {
        //Double mark = tstId;
        //String tetId = tstId.split(",")[3];
        objDataset.addValue(marks, "Line1", marks);

    }
    for (Double marks : girlsAvg) {
        //Double mark = tstId;
        //String tetId = tstId.split(",")[3];
        objDataset.addValue(marks, "Line2", marks);

    }
    //        for (Double testMark : bAvgList) {
    //            Double mark = testMark;
    //            //String tstId = testId.split(",")[3];
    //            objDataset.setValue(mark, "", mark);
    //            
    //            
    //        }
    JFreeChart objChart = ChartFactory.createLineChart("Marks Chart", //Chart title
            "Test", //Domain axis label
            "Marks", //Range axis label
            objDataset, //Chart Data 
            PlotOrientation.VERTICAL, // orientation
            true, // include legend?
            true, // include tooltips?
            false // include URLs?
    );

    ChartFrame frame = new ChartFrame("Dakma Higher Education Center", objChart);
    frame.setLocationRelativeTo(frame);
    frame.pack();
    frame.setVisible(true);
}

From source file:jsdp.app.inventory.univariate.CapacitatedStochasticLotSizing.java

static void plotOptimalPolicyAction(int targetPeriod, BackwardRecursionImpl recursion) {
    XYSeries series = new XYSeries("Optimal policy");
    for (double i = StateImpl.getMinState(); i <= StateImpl.getMaxState(); i += StateImpl.getStepSize()) {
        StateDescriptorImpl stateDescriptor = new StateDescriptorImpl(targetPeriod, i);
        series.add(i, recursion.getOptimalAction(stateDescriptor).getAction());
    }/*from  w w w  .  jav a 2 s. co  m*/

    XYDataset xyDataset = new XYSeriesCollection(series);
    JFreeChart chart = ChartFactory.createXYLineChart(
            "Optimal policy - period " + targetPeriod + " order quantity", "Opening inventory level",
            "Order quantity", xyDataset, PlotOrientation.VERTICAL, false, true, false);
    ChartFrame frame = new ChartFrame("Optimal policy", chart);
    frame.setVisible(true);
    frame.setSize(500, 400);
}

From source file:jsdp.app.inventory.univariate.CapacitatedStochasticLotSizing.java

static void plotOptimalPolicyCost(int targetPeriod, BackwardRecursionImpl recursion) {
    recursion.runBackwardRecursion(targetPeriod);
    XYSeries series = new XYSeries("Optimal policy");
    for (double i = StateImpl.getMinState(); i <= StateImpl.getMaxState(); i += StateImpl.getStepSize()) {
        StateDescriptorImpl stateDescriptor = new StateDescriptorImpl(targetPeriod, i);
        series.add(i, recursion.getExpectedCost(stateDescriptor));
    }/*w  w w .  jav  a  2 s.c  o m*/
    XYDataset xyDataset = new XYSeriesCollection(series);
    JFreeChart chart = ChartFactory.createXYLineChart(
            "Optimal policy policy - period " + targetPeriod + " expected total cost",
            "Opening inventory level", "Expected total cost", xyDataset, PlotOrientation.VERTICAL, false, true,
            false);
    ChartFrame frame = new ChartFrame("Optimal policy", chart);
    frame.setVisible(true);
    frame.setSize(500, 400);
}

From source file:jsdp.app.inventory.univariate.StochasticLotSizing.java

static void plotOptimalPolicyCost(int targetPeriod, BackwardRecursionImpl recursion) {
    recursion.runBackwardRecursionMonitoring(targetPeriod);
    XYSeries series = new XYSeries("Optimal policy");
    for (double i = StateImpl.getMinState(); i <= StateImpl.getMaxState(); i += StateImpl.getStepSize()) {
        StateDescriptorImpl stateDescriptor = new StateDescriptorImpl(targetPeriod, i);
        series.add(i, recursion.getExpectedCost(stateDescriptor));
    }/*from  w w w  .  ja va2s.  co m*/
    XYDataset xyDataset = new XYSeriesCollection(series);
    JFreeChart chart = ChartFactory.createXYLineChart(
            "Optimal policy policy - period " + targetPeriod + " expected total cost",
            "Opening inventory level", "Expected total cost", xyDataset, PlotOrientation.VERTICAL, false, true,
            false);
    ChartFrame frame = new ChartFrame("Optimal policy", chart);
    frame.setVisible(true);
    frame.setSize(500, 400);
}