Criacao de graficos

5 respostas
MarcelComputacao

olah comunidade,

estou querendo aprender criar graficos :lol:. Nao tenho a minima de ideia como faço isso. Alguem pode me dar um exemplo de programa que gera grafico(s) ?  :roll: . Ou pode me indicar apostilas, tutoriais, livros que ensinam ?  :roll: .

desde já agradeço. :wink:

5 Respostas

H

Que tipo de graficos?
tem iReports e JFreechart
a sua escolha =D

Petronio_Braga

Marcel,

dá uma olhada nesse link aqui:

http://www.java2s.com/Code/Java/Chart/CatalogChart.htm

Esses exemplos usam o JFreeChart. O site do JfreeChart é http://www.jfree.org/index.php

andredeividi

vc tera de adiconar as apis JFreeChart

/* ===========================================================
 * JFreeChart : a free chart library for the Java(tm) platform
 * ===========================================================
 *
 * (C) Copyright 2000-2004, by Object Refinery Limited and Contributors.
 *
 * Project Info:  http://www.jfree.org/jfreechart/index.html
 *
 * This library is free software; you can redistribute it and/or modify it under the terms
 * of the GNU Lesser General Public License as published by the Free Software Foundation;
 * either version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License along with this
 * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
 * in the United States and other countries.]
 *
 * ---------------
 * GanttDemo2.java
 * ---------------
 * (C) Copyright 2003, 2004, by Object Refinery Limited.
 *
 * Original Author:  David Gilbert (for Object Refinery Limited);
 * Contributor(s):   -;
 *
 * $Id: GanttDemo2.java,v 1.12 2004/04/26 19:11:54 taqua Exp $
 *
 * Changes
 * -------
 * 10-Jan-2003 : Version 1 (based on GanttDemo1) (DG);
 * 16-Sep-2003 : Transferred dataset creation from DemoDatasetFactory to this class (DG);
 *
 */

package com.softin.aginesNetwork.gui.forms;
import java.awt.Color;
import java.awt.Dimension;
import java.util.Calendar;
import java.util.Date;
import javax.swing.JPanel;
import org.jfree.chart.*;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.renderer.category.CategoryItemRenderer;
import org.jfree.data.category.IntervalCategoryDataset;
import org.jfree.data.gantt.*;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
import org.joda.time.DateTime;

public class GanttDemo2 extends ApplicationFrame
{

    public GanttDemo2(String s)
    {
        super(s);
        IntervalCategoryDataset intervalcategorydataset = createDataset();
        JFreeChart jfreechart = createChart(intervalcategorydataset);
        ChartPanel chartpanel = new ChartPanel(jfreechart);
        chartpanel.setPreferredSize(new Dimension(500, 270));
        setContentPane(chartpanel);
    }

    private static JFreeChart createChart(IntervalCategoryDataset intervalcategorydataset)
    {
        JFreeChart jfreechart = ChartFactory.createGanttChart("Ordem de Produção", "Maquina", "Data", intervalcategorydataset, true, true, false);
        CategoryPlot categoryplot = (CategoryPlot)jfreechart.getPlot();
        categoryplot.getDomainAxis().setMaximumCategoryLabelWidthRatio(10F);
        CategoryItemRenderer categoryitemrenderer = categoryplot.getRenderer();
        categoryitemrenderer.setSeriesPaint(0, Color.blue);
        return jfreechart;
    }

    private static IntervalCategoryDataset createDataset()
    {
        TaskSeries taskseries = new TaskSeries("Previsto");
        Task task = new Task("op -0001", dateTime(1, 3, 2001,02,30), dateTime(5, 3, 2006,03,41));
        task.setPercentComplete(1.50);
        taskseries.add(task);
        
        Task task1 = new Task("Fresa", dateTime(1,3, 2001,1,30), dateTime(5, 2, 2002,1,50));
        task1.setPercentComplete(0.15);
        taskseries.add(task1);
        
        /*
        Task task2 = new Task("Op2", date(1,1, 2002), date(5, 2, 2003));
        task2.setPercentComplete(1.5);
        taskseries.add(task2);
        
        Task task3 = new Task("Op3", date(1,1, 2003), date(5, 2, 2004));
        task3.setPercentComplete(0.40);
        taskseries.add(task3);
        
        Task task4 = new Task("Op4", date(1,1, 2004), date(5, 2, 2005));
        task4.setPercentComplete(0.30);
        taskseries.add(task4);
        */
        
        
       
        TaskSeriesCollection taskseriescollection = new TaskSeriesCollection();
        taskseriescollection.add(taskseries);
        return taskseriescollection;
    }

    private static Date dateTime(int i, int j, int k,int l,int m)
    {
        Calendar calendar = Calendar.getInstance();
        calendar.set(k, j, i,l,m);
        Date date1 = calendar.getTime();
        return date1;
    }

    public static JPanel createDemoPanel()
    {
        JFreeChart jfreechart = createChart(createDataset());
        return new ChartPanel(jfreechart);
    }

    public static void main(String args[])
    {
        GanttDemo2 ganttdemo2 = new GanttDemo2("Agines Network Ordem de Produção");
        ganttdemo2.pack();
        RefineryUtilities.centerFrameOnScreen(ganttdemo2);
        ganttdemo2.setVisible(true);
    }
}
neohacker

cara desculpa a santa ignorancia mais assim, eu sou novato no Java e to usando o eclipse, e assim eu tenho um arquivo .zip do jfreechart e add ele no meu projeto, mas não consigo usar ele assim msm, dai eu descompactei o zip e gerei a pasta do jfrrechart, e fui add um novo jar e então passei este caminho “jfreechart/lib/jfreechart.jar” e entaum reconheceu varias coisas, mas ainda está dando problema em “org.jfree.ui.*”.
Se vc pudesse me dar um help eu agradeceria mano…

andredeividi

ae

as libs são essas

gnujaxp.jar
itext-1.4.3.jar
jcommon-1.0.5.jar
jfreechart-1.0.2.jar
jfreechart-1.0.2-experimental.jar essa não tenho certeza

Abraço

Criado 13 de outubro de 2006
Ultima resposta 20 de abr. de 2007
Respostas 5
Participantes 5