Example usage for org.jfree.chart ChartFactory createLineChart

List of usage examples for org.jfree.chart ChartFactory createLineChart

Introduction

In this page you can find the example usage for org.jfree.chart ChartFactory createLineChart.

Prototype

public static JFreeChart createLineChart(String title, String categoryAxisLabel, String valueAxisLabel,
        CategoryDataset dataset) 

Source Link

Document

Creates a line chart with default settings.

Usage

From source file:br.unesp.rc.desafio.utils.Utils.java

public static void createLine(DefaultCategoryDataset dataset) {
    JFreeChart chart = ChartFactory.createLineChart("Grafico", " ", " ", dataset);
    CategoryPlot p = chart.getCategoryPlot();
    p.setRangeGridlinePaint(Color.black);
    ChartFrame frame = new ChartFrame("Grafico de BArras", chart);
    frame.setVisible(true);/*from w ww.j  a va 2  s .c  o m*/
    frame.setSize(400, 350);
    ManagerGUI.centralizar(frame);

}

From source file:controle.JfreeChartController.java

@PostConstruct
public void init() {
    try {//from  w  w w  . ja v a  2  s.  com
        //Graphic Text
        BufferedImage bufferedImg = new BufferedImage(100, 25, BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = bufferedImg.createGraphics();
        g2.drawString("This is a text", 0, 10);
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        ImageIO.write(bufferedImg, "png", os);
        graphicText = new DefaultStreamedContent(new ByteArrayInputStream(os.toByteArray()), "image/png");

        //Chart
        JFreeChart jfreechart = ChartFactory.createLineChart("cosseno", "X", "Y", createDataset());
        File chartFile = new File("dynamichart");
        ChartUtilities.saveChartAsPNG(chartFile, jfreechart, 800, 400);
        chart = new DefaultStreamedContent(new FileInputStream(chartFile), "image/png");
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.jfree.graphics2d.demo.SVGBarChartDemo1.java

/**
 * Creates a sample chart.// w  ww. j  ava  2 s.  c o m
 *
 * @param dataset  a dataset.
 *
 * @return The chart.
 */
private static JFreeChart createChart(CategoryDataset dataset) {

    JFreeChart chart = ChartFactory.createLineChart("Statistical Bar Chart Demo 1", "Type", "Value", dataset);

    CategoryPlot plot = (CategoryPlot) chart.getPlot();

    // customise the range axis...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setAutoRangeIncludesZero(false);

    // customise the renderer...
    StatisticalBarRenderer renderer = new StatisticalBarRenderer();
    renderer.setDrawBarOutline(false);
    renderer.setErrorIndicatorPaint(Color.black);
    renderer.setIncludeBaseInRange(false);
    plot.setRenderer(renderer);

    // ensure the current theme is applied to the renderer just added
    ChartUtilities.applyCurrentTheme(chart);

    renderer.setDefaultItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setDefaultItemLabelsVisible(true);
    renderer.setDefaultItemLabelPaint(Color.yellow);
    renderer.setDefaultPositiveItemLabelPosition(
            new ItemLabelPosition(ItemLabelAnchor.INSIDE6, TextAnchor.BOTTOM_CENTER));

    // set up gradient paints for series...
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64));
    GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0));
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    return chart;
}

From source file:org.jfree.graphics2d.demo.CanvasBarChartDemo1.java

/**
 * Creates a sample chart.//from   w w w.  ja  va2 s .  co  m
 *
 * @param dataset  a dataset.
 *
 * @return The chart.
 */
private static JFreeChart createChart(CategoryDataset dataset) {

    // create the chart...
    JFreeChart chart = ChartFactory.createLineChart("Statistical Bar Chart Demo 1", // chart title
            "Type", // domain axis label
            "Value", // range axis label
            dataset);

    CategoryPlot plot = (CategoryPlot) chart.getPlot();

    // customise the range axis...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setAutoRangeIncludesZero(false);

    // customise the renderer...
    StatisticalBarRenderer renderer = new StatisticalBarRenderer();
    renderer.setDrawBarOutline(false);
    renderer.setErrorIndicatorPaint(Color.black);
    renderer.setIncludeBaseInRange(false);
    plot.setRenderer(renderer);

    // ensure the current theme is applied to the renderer just added
    ChartUtilities.applyCurrentTheme(chart);

    renderer.setDefaultItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setDefaultItemLabelsVisible(true);
    renderer.setDefaultItemLabelPaint(Color.yellow);
    renderer.setDefaultPositiveItemLabelPosition(
            new ItemLabelPosition(ItemLabelAnchor.INSIDE6, TextAnchor.BOTTOM_CENTER));

    // set up gradient paints for series...
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64));
    GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0));
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    return chart;
}

From source file:datavis.Gui.java

private void initGraphs(DataList dataset) {

    //Initialize the GUI with default, blank sample graphs
    //That serve as place holders for that actual content

    //Create Pie Chart
    PieChart samplePie = new PieChart("Sample Data");
    samplePie.addData("Default Value", 1.0);
    JFreeChart chart = samplePie.getChartPanel();

    //Add chart to GUI
    javax.swing.JPanel chartPanel = new ChartPanel(chart);
    chartPanel.setSize(jPanel1.getSize());
    jPanel1.add(chartPanel);//from w  w  w.  j a  v a2  s. co  m
    jPanel1.getParent().validate();

    //Create Line graph
    DefaultCategoryDataset sampleLine = new DefaultCategoryDataset();
    sampleLine.setValue(1.0, "sample Data", "Sample Data");
    JFreeChart chart2 = ChartFactory.createLineChart("Sample Data", "Sample", "Sample", sampleLine);

    //Add chart to GUI
    javax.swing.JPanel chartPanel2 = new ChartPanel(chart2);
    chartPanel2.setSize(jPanel2.getSize());
    jPanel2.add(chartPanel2);
    jPanel2.getParent().validate();

    //Create bar graph
    DefaultCategoryDataset sampleBar = new DefaultCategoryDataset();
    sampleLine.setValue(1.0, "sample Data", "Sample Data");
    JFreeChart chart3 = ChartFactory.createBarChart("Sample Data", "Sample", "Sample", sampleBar);

    //Add chart to GUI
    javax.swing.JPanel chartPanel3 = new ChartPanel(chart3);
    chartPanel3.setSize(jPanel3.getSize());
    jPanel3.add(chartPanel3);
    jPanel3.getParent().validate();

    //Set the author information to the info box
    jTextArea2.setText(displayDevelopers);
}

From source file:UserInterface.AppUsersProfile.DetailAnalysis.DetailAnalysisJPanel.java

public ChartPanel getChartPanel(String vitalSignType) {

    int count = 1;
    DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
    for (VitalSign vitalSign : userAccount.getPatient().getVitalSignHistory().getVitalSignList()) {
        String str = String.valueOf(count);
        if (vitalSignType.equalsIgnoreCase("Blood Pressure")) {
            vitalSignType = "Blood Pressure";
            dataSet.addValue(vitalSign.getBloodPressure(), "Blood Pressure", str);
        } else if (vitalSignType.equalsIgnoreCase("Pulse Rate")) {
            vitalSignType = "Pulse Rate";
            dataSet.addValue(vitalSign.getHeartRate(), "Pulse Rate", str);
        } else if (vitalSignType.equalsIgnoreCase("Respiratory Rate")) {
            vitalSignType = "Respiratory Rate";
            dataSet.addValue(vitalSign.getRespiratoryRate(), "Respiratory Rate", str);
        } else if (vitalSignType.equalsIgnoreCase("Temperature")) {
            vitalSignType = "Temperature";
            dataSet.addValue(vitalSign.getTemperature(), "Temperature", str);
        }/* ww w  . j  a  va2 s.  c o  m*/
        count++;
    }
    JFreeChart chartFactory = ChartFactory.createLineChart(vitalSignType + " Chart", "Timestamp", vitalSignType,
            dataSet);
    CategoryPlot plot = chartFactory.getCategoryPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setRangeGridlinePaint(Color.blue);
    ChartPanel chartPanel = new ChartPanel(chartFactory);
    return chartPanel;
}

From source file:cherry.chart.app.LineChartBatch.java

@Override
public ExitStatus execute(String... args) {

    int nThread = (args.length < 1 ? defaultNumThread : parseInt(args[0]));
    int count = (args.length < 2 ? defaultCount : parseInt(args[1]));

    ExecutorService executorService = Executors.newFixedThreadPool(nThread);
    List<Future<Boolean>> tasks = new LinkedList<>();

    for (int i = 0; i < count; i++) {

        final String numStr = String.valueOf(i);
        tasks.add(executorService.submit(new Callable<Boolean>() {
            @Override/*from   ww w  .j a  v a 2  s.  c  o  m*/
            public Boolean call() {

                File f = new File(toDir, format(file, numStr));
                String t = format(title, numStr);

                CategoryDataset dataset = createDataset();
                JFreeChart chart = ChartFactory.createLineChart(t, xLabel, yLabel, dataset);

                try (OutputStream out = new FileOutputStream(f)) {
                    ChartUtilities.writeChartAsPNG(out, chart, width, height);
                    return true;
                } catch (IOException ex) {
                    log.error("failed to create file", ex);
                    return false;
                }
            }
        }));
    }

    boolean success = true;
    for (Future<Boolean> future : tasks) {
        try {
            success &= future.get();
        } catch (ExecutionException | InterruptedException ex) {
            log.error("failed to get result", ex);
            success = false;
        }
    }
    return (success ? ExitStatus.NORMAL : ExitStatus.ERROR);
}

From source file:vn.edu.vttu.ui.PanelStatiticsRevenue.java

private void showChart(String title, String begin, String end) {
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    int row = tbResult.getRowCount();
    for (int i = 0; i < row; i++) {
        float value = 0;
        try {/* www  .ja va 2s  . co  m*/
            try {
                value = Float.parseFloat(String.valueOf(tbResult.getValueAt(i, 3)).trim().replaceAll("\\.", ""))
                        / 1000;
            } catch (Exception e) {
                value = Float.parseFloat(String.valueOf(tbResult.getValueAt(i, 3)).trim().replaceAll(",", ""))
                        / 1000;
            }
        } catch (Exception e) {
            value = 0;
        }
        String date = String.valueOf(tbResult.getValueAt(i, 0)).trim();

        dataset.addValue(value, "Doanh Thu", date);
    }

    JFreeChart chart = ChartFactory.createLineChart(
            "TH?NG K DOANH THU\nT " + title + " " + begin + " ?N " + title + " " + end, title,
            "S Ti?n(?n v: nghn ng)", dataset);
    CategoryPlot p = chart.getCategoryPlot();
    p.setRangeGridlinePaint(Color.black);
    ChartPanel CP = new ChartPanel(chart);
    pnChart.removeAll();
    pnChart.add(CP);
    pnChart.updateUI();
    pnChart.repaint();
    //ChartFrame frame = new ChartFrame("Thng k doanh thu", chart);
    //frame.setSize(450, 350);
    //frame.setVisible(true);
}

From source file:controle.AgController.java

public void execute() {
    long tempoInicial = System.currentTimeMillis();

    ag.run();/*from  w w  w.j av a2  s  .  c  o  m*/
    ChartSeries melhores = new ChartSeries();
    melhores.setLabel("Melhores");

    ChartSeries piores = new ChartSeries();
    piores.setLabel("Piores");

    ChartSeries desvioPadrao = new ChartSeries();
    desvioPadrao.setLabel("Desvio Padro");

    ChartSeries media = new ChartSeries();
    media.setLabel("Mdia");

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    for (int i = 0; i < ag.getMelhoresIndividuos().size(); i++) {
        melhores.set(i, ag.getMelhoresIndividuos().get(i).getFitness());
        piores.set(i, ag.getPioresIndividuos().get(i).getFitness());
        desvioPadrao.set(i, ag.getDesvioPadrao().get(i));
        media.set(i, ag.getMedia().get(i));
        dataset.addValue(ag.getMelhoresIndividuos().get(i).getFitness(), "melhores", Integer.valueOf(i));

    }
    model.addSeries(melhores);
    model.addSeries(piores);
    model.addSeries(desvioPadrao);
    model.addSeries(media);
    model.setTitle("Desempenho por Geraes");
    model.setLegendPosition("e"); //nw
    model.setAnimate(true);
    model.setSeriesColors("00cc00,cc0000,e5e55f,0099ff");

    try {
        JFreeChart jfreechart = ChartFactory.createLineChart("Melhores", "Geraes", "Fitness", dataset);
        File chartFile = new File("dynamichart");
        ChartUtilities.saveChartAsPNG(chartFile, jfreechart, 600, 400);
        chart = new DefaultStreamedContent(new FileInputStream(chartFile), "image/png");
    } catch (Exception e) {
        e.printStackTrace();
    }

    long tempoFinal = System.currentTimeMillis();
    tempoExecucao = (tempoFinal - tempoInicial) / 1000;

}

From source file:Questao3.java

/**
 * Metodo cria e exibe o grfico da media dos pixels das imagens resultantes
 * @throws IOException/* w  w w .  ja  v  a 2s .  c  om*/
 */
public void criaGrafico() throws IOException {
    CategoryDataset cds = createDataset();
    String titulo = "Mdia da Primeira linha de pixels";
    String eixoy = "Valores";
    String txt_legenda = "Pixels";
    boolean legenda = true;
    boolean tooltips = true;
    boolean urls = true;
    JFreeChart graf = ChartFactory.createLineChart(titulo, txt_legenda, eixoy, cds);
    File lineChart = new File("grafico.jpeg");
    ChartUtilities.saveChartAsJPEG(lineChart, graf, 512, 256);
    showResult("grafico.jpeg");
}