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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
| import java.awt.Color;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.CategoryItemRenderer;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.general.DatasetUtilities;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
import java.awt.geom.Ellipse2D;
import javax.swing.*;
/**
* A simple demonstration application showing how to create a
* stacked XY area chart.
*
*/
public class Reviere extends JFrame {
Number [] mini;
Number [] maxi;
Number[] actu;
Number[] futu;
String ville = new String();
public Reviere(final String title,Number[] min, Number [] max, Number[] act, Number[] fut,ListModel nomP) {
super(title);
ville = title;
mini=min;
maxi= max;
actu=act;
futu= fut;
CategoryDataset dataset = createDataset();
JFreeChart chart = createChart(dataset);
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
setContentPane(chartPanel);
}
public CategoryDataset createDataset() {
final Number[][] data = new Number[3][maxi.length];
for (int i=0; i<mini.length;i++)
{
data[0][i]= mini[i];
}
for (int j=0; j<maxi.length;j++)
{
int n1 = maxi[j].intValue();
int n2 = mini[j].intValue();
Number n3 = n1-n2;
data[1][j]= n3;
}
for (int j=0; j<maxi.length;j++)
{
int n1 = maxi[j].intValue();
int n2 = mini[j].intValue();
Number n3 = 5-(n1-n2)-n2;
data[2][j]= n3;
}
final CategoryDataset dataset = DatasetUtilities.createCategoryDataset(
"Series ", "Pratique ", data
);
return dataset;
}
/**
* Creates a sample chart.
*
* @param dataset the dataset.
*
* @return A sample chart.
*/
public JFreeChart createChart(CategoryDataset dataset) {
final JFreeChart chart = ChartFactory.createStackedAreaChart(
ville, // chart title
"Pratiques", // domain axis label
"Notes", // range axis label
dataset, // data
PlotOrientation.VERTICAL, // orientation
true, // include legend
true,
false
);
chart.setBackgroundPaint(Color.white);
final CategoryPlot plot = (CategoryPlot) chart.getPlot();
plot.setForegroundAlpha(0.5f);
plot.setBackgroundPaint(Color.lightGray);
plot.setDomainGridlinePaint(Color.white);
plot.setRangeGridlinePaint(Color.white);
final CategoryAxis domainAxis = plot.getDomainAxis();
domainAxis.setLowerMargin(0.0);
domainAxis.setUpperMargin(0.0);
// change the auto tick unit selection to integer units only...
final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
final CategoryItemRenderer renderer = plot.getRenderer();
renderer.setItemLabelsVisible(true);
renderer.setSeriesPaint(0,Color.GREEN);
renderer.setSeriesPaint(2,Color.GREEN);
renderer.setSeriesPaint(1,Color.BLUE);
renderer.setShape(new Ellipse2D.Double(-3, -3, 6, 6));
return chart;
}
} |
Partager