Gerando gráficos

Olá, pessoal.
Preciso trocar uma tabela que criei em java por um gráfico em minha aplicação,
e gostaria de saber como faço isso.
Tem algum tutorial?
Parece que terei de usar o \jfreechart, mas ele é pago?
Como faço isso?
Desde já, obrigado! :slight_smile:

Sua aplicacao é Web ou Swing ?

É Swing! :slight_smile:

Isso mesmo com jfreechart vc consegue gerar os graficos. Segue um link caso nao consiga tenho outros exemplos, dai t envio.
Se precisar segunda posso te passar umas classes prontas já q utilizo para geraçao de grafico no swing.

http://www.webforefront.com/about/danielrubio/articles/ostg/jfreechart.html

[quote=vdb]Isso mesmo com jfreechart vc consegue gerar os graficos. Segue um link caso nao consiga tenho outros exemplos, dai t envio.
Se precisar segunda posso te passar umas classes prontas já q utilizo para geraçao de grafico no swing.

http://www.webforefront.com/about/danielrubio/articles/ostg/jfreechart.html[/quote]

Importei os jars da jfrrechar para o meu diretório apropriado e tentei compilar a classe abaixo que consta no exemplo, mas deu erro . . .

C:\backup\Evandro\Java\ChamadaPlanilhaExcel\TheFuture.java:8: cannot find symbol
symbol : class XYSeries
location: class TheFuture
XYSeries series = new XYSeries(“Linux Users”);

import org.jfree.chart.*;
import org.jfree.data.*;

public class TheFuture {

    public static void main(String[] args) {

	XYSeries series = new XYSeries("Linux Users");
	series.add(1995, 0.5);
	series.add(2000, 3.0);
	series.add(2010, 20.0);
	series.add(2020, 50.0);
	XYDataset dataset = new XYSeriesCollection(series);

	JFreeChart chart = ChartFactory.createXYAreaChart(
	     "Linux Users",
	     "Year",
	     "Millions",
	     dataset,
             org.jfree.chart.plot.PlotOrientation.VERTICAL,
	     true,
	     false,
             false);

	try {
	  ChartUtilities.saveChartAsJPEG(
          new java.io.File("TheFuture.jpg"), chart, 500, 300);
	} catch (java.io.IOException exc) {
	    System.err.println("Error writing image to file");
	}
    }
}

[quote=evandrolnr][quote=vdb]Isso mesmo com jfreechart vc consegue gerar os graficos. Segue um link caso nao consiga tenho outros exemplos, dai t envio.
Se precisar segunda posso te passar umas classes prontas já q utilizo para geraçao de grafico no swing.

http://www.webforefront.com/about/danielrubio/articles/ostg/jfreechart.html[/quote]

Importei os jars da jfrrechar para o meu diretório apropriado e tentei compilar a classe abaixo que consta no exemplo, mas deu erro . . .

C:\backup\Evandro\Java\ChamadaPlanilhaExcel\TheFuture.java:8: cannot find symbol
symbol : class XYSeries
location: class TheFuture
XYSeries series = new XYSeries(“Linux Users”);

import org.jfree.chart.*;
import org.jfree.data.*;

public class TheFuture {

    public static void main(String[] args) {

	XYSeries series = new XYSeries("Linux Users");
	series.add(1995, 0.5);
	series.add(2000, 3.0);
	series.add(2010, 20.0);
	series.add(2020, 50.0);
	XYDataset dataset = new XYSeriesCollection(series);

	JFreeChart chart = ChartFactory.createXYAreaChart(
	     "Linux Users",
	     "Year",
	     "Millions",
	     dataset,
             org.jfree.chart.plot.PlotOrientation.VERTICAL,
	     true,
	     false,
             false);

	try {
	  ChartUtilities.saveChartAsJPEG(
          new java.io.File("TheFuture.jpg"), chart, 500, 300);
	} catch (java.io.IOException exc) {
	    System.err.println("Error writing image to file");
	}
    }
}

[/quote]

descobri o que estava errado! :slight_smile:
Se eu substituir os imports do programa acima (com erro) por:
import org.jfree.chart.;
import org.jfree.data.xy.
;
aí compila e executa, gerando uma imagem no disco rígido.

A dúvida agora é outra: Como faço para adicionar o gráfico gerado em um JPanel?

jPanel = new JPanel();
criarGrafico(); // meu método que cria o objeto chart do exemplo acima
jPanel.add( chart ); // dá erro de compilação aqui

cannot find symbol
symbol : method add(org.jfree.chart.JFreeChart)