pumapc
28-09-2012, 11:01
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:
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)
Per prima cosa ho copiato i vari JAR, presenti nella cartella lib del pacchetto JFreeChart, in una cartella appositamente creata AO_JAVA_LIB e ho provato ad eseguire il seguente script di esempio trovato su internet che incollo qui di seguito:
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
}
}
Provandolo a complilare passandogli l'opzione -classpath mi restituisce il seguente errore:
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
Ho provato ad usare appunto la versione precedente cioè la JFreeChart 1.0.13 e non l'ultima la JFreeChart 1.0.14 per vedere se, essendo meno recente, non mi desse l'errore...
Come potrei risolvere?
Grazie in anticipo per l'aiuto.
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:
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)
Per prima cosa ho copiato i vari JAR, presenti nella cartella lib del pacchetto JFreeChart, in una cartella appositamente creata AO_JAVA_LIB e ho provato ad eseguire il seguente script di esempio trovato su internet che incollo qui di seguito:
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
}
}
Provandolo a complilare passandogli l'opzione -classpath mi restituisce il seguente errore:
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
Ho provato ad usare appunto la versione precedente cioè la JFreeChart 1.0.13 e non l'ultima la JFreeChart 1.0.14 per vedere se, essendo meno recente, non mi desse l'errore...
Come potrei risolvere?
Grazie in anticipo per l'aiuto.