1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
DefaultCategoryDataset data1 = new DefaultCategoryDataset();
data1.addValue(1,"Importation","Zn");
data1.addValue(10,"Importation","Al");
data1.addValue(5,"Importation","CU");
data1.addValue(40,"Importation","Fe");
DefaultCategoryDataset data2 = new DefaultCategoryDataset();
data2.addValue(6,"Exportation","Zn");
data2.addValue(3,"Exportation","Al");
data2.addValue(8,"Exportation","CU");
data2.addValue(19,"Exportation","Fe");
JFreeChart jfreechart = ChartFactory.createLineChart("Test", "Category", "En £",
data1, PlotOrientation.VERTICAL, false, true, false);
jfreechart.setBackgroundPaint(Color.white);
CategoryPlot categoryplot = (CategoryPlot)jfreechart.getPlot();
CategoryItemRenderer renderer2 = new LineAndShapeRenderer();
categoryplot.setDataset(1, data2);
categoryplot.mapDatasetToRangeAxis(1, 0);
categoryplot.setRenderer(1, renderer2);
LegendTitle legendtitle1 = new LegendTitle(categoryplot.getRenderer(0));
legendtitle1.setItemPaint(Color.RED);
// LegendTitle legendtitle2 = new LegendTitle(categoryplot.getRenderer(1));
// legendtitle2.setItemPaint(Color.BLUE);
BlockContainer blockcontainer = new BlockContainer(new BorderArrangement());
blockcontainer.add(legendtitle1, RectangleEdge.BOTTOM);
// blockcontainer.add(legendtitle2, RectangleEdge.RIGHT);
CompositeTitle compositetitle = new CompositeTitle(blockcontainer);
compositetitle.setPosition(RectangleEdge.LEFT);
jfreechart.addSubtitle(compositetitle);
File fichier = new File("C:\\Test.png");
try {
ChartUtilities.saveChartAsPNG(fichier, jfreechart,500,270);
} catch (IOException e) {
e.printStackTrace();
}
} |
Partager