|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Member
Iscritto dal: Nov 2007
Messaggi: 93
|
[JAVA] Script per creazione grafici con libreria JFreeChart
Ciao a tutti,
chiedo il vostro supporto in quanto vorrei creare uno script in JAVA che mi faccia il grafico in base ad alcuni valori presi da un file. Per far ciò leggendo su internet ho visto che la miglior libreria è la seguente JFreeChart. Premetto che lavoro nelle telecomunicazioni come sistemista applicativo e non posso lavorare in locale in quanto tale script deve girare sulle varie macchine dove utiliziamo Unix e quindi mi devo adattare a ciò che è già installato sui vari server... La versione JRE installata è la seguente: Codice:
java version "1.5.0_06" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05) Java HotSpot(TM) 64-Bit Server VM (build 1.5.0_06-b05, mixed mode) Codice:
import java.io.File;
import java.io.IOException;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PiePlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.util.Rotation;
public class TestStatistiche {
public static void main(String[] args) throws IOException {
// tre valori riempiti staticamente
int value1 = 12;
int value2 = 20;
int value3 = 40;
// istrogramma a barre verticali/orizzontali
DefaultCategoryDataset cdata = new DefaultCategoryDataset();
cdata.setValue(value1, "value1: " +value1, "colonna1");
cdata.setValue(value2, "value2: " +value2, "colonna2");
cdata.setValue(value3, "value3: " +value3, "colonna3");
// PlotOrientation.VERTICAL per cambiare l'orientamento delle barre
JFreeChart chart = ChartFactory.createBarChart("value1", "value2", "value3", cdata, PlotOrientation.HORIZONTAL, true, true, true);
ChartUtilities.saveChartAsJPEG(new File("C:\\istogramma.jpg"), chart, 400, 450); // larghezza 400; altezza 450
// diagramma torta 3d
DefaultPieDataset data = new DefaultPieDataset();
data.setValue("value1: " +value1, value1);
data.setValue("value2: " +value2, value2);
data.setValue("value3: " +value3, value3);
JFreeChart chart2 = ChartFactory.createPieChart3D("Statistiche", data, true, true, true);
ChartUtilities.saveChartAsPNG(new File("C:\\torta1.png"), chart2, 400, 450); // larghezza 400; altezza 450
// applichiamo effetti grafici al diagramma torta 3d
PiePlot plot = (PiePlot) chart2.getPlot();
plot.setStartAngle(290);
plot.setDirection(Rotation.CLOCKWISE);
plot.setForegroundAlpha(0.5f);
ChartUtilities.saveChartAsPNG(new File("C:\\torta2.png"), chart2, 400, 450); // larghezza 400; altezza 450
}
}
Codice:
javac -classpath .:/BIN/AO_JAVA_LIB/jfreechart-1.0.13.jar:/BIN/AO_JAVA_LIB/jcommon-1.0.16.jar:/BIN/AO_JAVA_LIB/jfreechart-1.0.13-swt.jar TestStatistiche.java
error: Invalid class file format in /BIN/AO_JAVA_LIB/jfreechart-1.0.13.jar(org/jfree/chart/ChartFactory.class). The major.minor version '47.0' is too recent for this tool to understand.
TestStatistiche.java:3: Class org.jfree.chart.ChartFactory not found in import.
import org.jfree.chart.ChartFactory;
^
error: Invalid class file format in /BIN/AO_JAVA_LIB/jfreechart-1.0.13.jar(org/jfree/chart/ChartUtilities.class). The major.minor version '47.0' is too recent for this tool to understand.
TestStatistiche.java:4: Class org.jfree.chart.ChartUtilities not found in import.
import org.jfree.chart.ChartUtilities;
^
error: Invalid class file format in /BIN/AO_JAVA_LIB/jfreechart-1.0.13.jar(org/jfree/chart/JFreeChart.class). The major.minor version '47.0' is too recent for this tool to understand.
TestStatistiche.java:5: Class org.jfree.chart.JFreeChart not found in import.
import org.jfree.chart.JFreeChart;
^
error: Invalid class file format in /BIN/AO_JAVA_LIB/jfreechart-1.0.13.jar(org/jfree/chart/plot/PiePlot.class). The major.minor version '47.0' is too recent for this tool to understand.
TestStatistiche.java:6: Class org.jfree.chart.plot.PiePlot not found in import.
import org.jfree.chart.plot.PiePlot;
^
error: Invalid class file format in /BIN/AO_JAVA_LIB/jfreechart-1.0.13.jar(org/jfree/chart/plot/PlotOrientation.class). The major.minor version '47.0' is too recent for this tool to understand.
TestStatistiche.java:7: Class org.jfree.chart.plot.PlotOrientation not found in import.
import org.jfree.chart.plot.PlotOrientation;
^
error: Invalid class file format in /BIN/AO_JAVA_LIB/jfreechart-1.0.13.jar(org/jfree/data/category/DefaultCategoryDataset.class). The major.minor version '47.0' is too recent for this tool to understand.
TestStatistiche.java:8: Class org.jfree.data.category.DefaultCategoryDataset not found in import.
import org.jfree.data.category.DefaultCategoryDataset;
^
error: Invalid class file format in /BIN/AO_JAVA_LIB/jfreechart-1.0.13.jar(org/jfree/data/general/DefaultPieDataset.class). The major.minor version '47.0' is too recent for this tool to understand.
TestStatistiche.java:9: Class org.jfree.data.general.DefaultPieDataset not found in import.
import org.jfree.data.general.DefaultPieDataset;
^
14 errors
Come potrei risolvere? Grazie in anticipo per l'aiuto. |
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Nov 2005
Città: Texas
Messaggi: 1722
|
Java 6 e' uscito nel 2006. Su sourceforge puoi trovare tutte le versioni rilasciate di jfreechart; magari potresti prima di tutto provarne una ancora piu' vecchia....
non puoi proprio installare una nuova versione di java?
__________________
In God we trust; all others bring data |
|
|
|
|
|
#3 | |
|
Member
Iscritto dal: Nov 2007
Messaggi: 93
|
Quote:
Quindi dici di prendere qualche versione rilascaita prima del 2006? tipo la versione 1.0.0 rilascata il 2005-12-02?? |
|
|
|
|
|
|
#4 |
|
Senior Member
Iscritto dal: Oct 2007
Città: Padova
Messaggi: 4131
|
Fossi in te proverei a chiedere informazioni circa quale versione usare nella tua sistuazione direttamente nel forum dedicato:
http://www.jfree.org/forum/viewforum.php?f=3 oppure scrivendo a uno degli sviluppatori (vedi pagina del progetto su sourceForge): sourceforge.net/projects/jfreechart/
__________________
As long as you are basically literate in programming, you should be able to express any logical relationship you understand. If you don’t understand a logical relationship, you can use the attempt to program it as a means to learn about it. (Chris Crawford) |
|
|
|
|
|
#5 | |
|
Senior Member
Iscritto dal: Nov 2005
Città: Texas
Messaggi: 1722
|
Quote:
__________________
In God we trust; all others bring data |
|
|
|
|
|
|
#6 |
|
Member
Iscritto dal: Nov 2007
Messaggi: 93
|
Ciao a tutti,
ho provato la versione 1.0.0 e a compilare va ma poi mi da un errore nel main: Codice:
/script_prd/USERS/ROBERTO -> javac -classpath .:/BIN/AO_JAVA_LIB/jcommon-1.0.0.jar:/BIN/AO_JAVA_LIB/jfreechart-1.0.0.jar TestStatistiche.java script_prd/USERS/ROBERTO -> /script_prd/USERS/ROBERTO -> /script_prd/USERS/ROBERTO -> java TestStatistiche Exception in thread "main" java.lang.NoClassDefFoundError: org/jfree/data/category/CategoryDataset Un'altra cosa... per poter installare l'ultima versione JRE in modo tale da poter utilizzare l'ultima versione e quindi non aver problemi di incompatibilità tra i vari metodi è possibile installare il JRE avendo i permessi di NON ROOT sul server? Cioè nello specifico io devo lanciare lo script che si trova su questa macchina e che ha questo sistema operativo: Codice:
uname -a SunOS XXXX 5.8 Generic_117350-62 sun4u sparc SUNW,Sun-Fire-15000 Se si dove posso trovare questa JRE per questo sistema Operativo? Perchè se riuscissi ad installare la versione nuova in locale risolverei tutti i problemi.. |
|
|
|
|
|
#7 | |
|
Senior Member
Iscritto dal: Nov 2005
Città: Texas
Messaggi: 1722
|
Quote:
__________________
In God we trust; all others bring data |
|
|
|
|
|
|
#8 | |
|
Member
Iscritto dal: Nov 2007
Messaggi: 93
|
Quote:
Codice:
java -classpath .:/ucs2/BIN/AO_JAVA_LIB/jcommon-1.0.0.jar:/ucs2/BIN/AO_JAVA_LIB/jfreechart-1.0.0.jar TestStatistiche.java Exception in thread "main" java.lang.NoClassDefFoundError: TestStatistiche/java |
|
|
|
|
|
|
#9 | |
|
Senior Member
Iscritto dal: Nov 2005
Città: Texas
Messaggi: 1722
|
Quote:
devi scrivere java -classpath <il tuo classpath, non posso verificarlo> TestStatistiche (non ci deve essere l'estensione .java poiche' sta andando a cercare la classe)
__________________
In God we trust; all others bring data |
|
|
|
|
|
|
#10 | |
|
Member
Iscritto dal: Nov 2007
Messaggi: 93
|
Quote:
ahhhh ecco ho tolto il .java ed ha funzionato... Mi ha generato i tre file.. Grazie mille per ora per l'aiuto!! Il test di esempio ha funzionato correttamente...il primo passo è stato fatto!! Ora inizierò a fare lo script per ciò che serve a me...e sicuramente vi scriverò ancora!! Grazie mille per l'aiuto!! |
|
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 13:36.



















