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 120 121 122 123 124 125 126 127 128
| ChartPanel getChart()
{
// create the chart...
JFreeChart chart = ChartFactory.createXYLineChart(
"Dimensions", // chart title
"Virolles", // x axis label
"", // y axis label
dataset_1, // data
PlotOrientation.VERTICAL,
true, // include legend
true, // tooltips
false // urls
);
// NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
// chart.setBackgroundPaint(Color.orange);
// get a reference to the plot for further customisation...
XYPlot plot = chart.getXYPlot();
// AXIS 1
NumberAxis axis1 = new NumberAxis("Weight");
axis1.setFixedDimension(10.0);
axis1.setAutoRangeIncludesZero(false);
axis1.setLabelPaint(Color.green);
axis1.setTickLabelPaint(Color.green);
plot.setRangeAxis(0, axis1);
plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_LEFT);
plot.setDataset(0, dataset_1);
plot.mapDatasetToRangeAxis(0, 0);
// AXIS 2
NumberAxis axis2 = new NumberAxis("IVir");
axis2.setFixedDimension(10.0);
axis2.setAutoRangeIncludesZero(false);
axis2.setLabelPaint(Color.blue);
axis2.setTickLabelPaint(Color.blue);
plot.setRangeAxis(1, axis2);
plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_LEFT);
plot.setDataset(1, dataset_2);
plot.mapDatasetToRangeAxis(1, 1);
// AXIS 3
NumberAxis axis3 = new NumberAxis("Raid");
axis3.setFixedDimension(10.0);
axis3.setAutoRangeIncludesZero(false);
axis3.setLabelPaint(Color.red);
axis3.setTickLabelPaint(Color.red);
plot.setRangeAxis(2, axis3);
plot.setRangeAxisLocation(2, AxisLocation.BOTTOM_OR_LEFT);
plot.setDataset(2, dataset_3);
plot.mapDatasetToRangeAxis(2, 2);
// AXIS 4
NumberAxis axis4 = new NumberAxis("Thick");
axis4.setFixedDimension(10.0);
axis4.setAutoRangeIncludesZero(false);
axis4.setLabelPaint(Color.cyan);
axis4.setTickLabelPaint(Color.cyan);
plot.setRangeAxis(3, axis4);
plot.setRangeAxisLocation(3, AxisLocation.BOTTOM_OR_RIGHT);
plot.setDataset(3, dataset_4);
plot.mapDatasetToRangeAxis(3, 3);
// AXIS 5
NumberAxis axis5 = new NumberAxis("Diameter");
axis5.setFixedDimension(10.0);
axis5.setAutoRangeIncludesZero(false);
axis5.setLabelPaint(Color.magenta);
axis5.setTickLabelPaint(Color.magenta);
plot.setRangeAxis(4, axis5);
plot.setRangeAxisLocation(4, AxisLocation.BOTTOM_OR_RIGHT);
plot.setDataset(4, dataset_5);
plot.mapDatasetToRangeAxis(4, 4);
// AXIS 4
NumberAxis axis6 = new NumberAxis("DiamSup");
axis6.setFixedDimension(10.0);
axis6.setAutoRangeIncludesZero(false);
axis6.setLabelPaint(Color.orange);
axis6.setTickLabelPaint(Color.orange);
plot.setRangeAxis(5, axis6);
plot.setRangeAxisLocation(5, AxisLocation.BOTTOM_OR_RIGHT);
plot.setDataset(5, dataset_6);
plot.mapDatasetToRangeAxis(5, 5);
XYItemRenderer renderer1 = new StandardXYItemRenderer();
XYItemRenderer renderer2 = new StandardXYItemRenderer();
XYItemRenderer renderer3 = new StandardXYItemRenderer();
XYItemRenderer renderer4 = new StandardXYItemRenderer();
XYItemRenderer renderer5 = new StandardXYItemRenderer();
XYItemRenderer renderer6 = new StandardXYItemRenderer();
renderer1.setSeriesPaint(0, Color.green);
renderer2.setSeriesPaint(0, Color.blue);
renderer3.setSeriesPaint(0, Color.red);
renderer4.setSeriesPaint(0, Color.cyan);
renderer5.setSeriesPaint(0, Color.magenta);
renderer6.setSeriesPaint(0, Color.orange);
plot.setRenderer(0, renderer1);
plot.setRenderer(1, renderer2);
plot.setRenderer(2, renderer3);
plot.setRenderer(3, renderer4);
plot.setRenderer(4, renderer5);
plot.setRenderer(5, renderer6);
// Marqueur 1
valuemarker1 = new ValueMarker(0);
valuemarker1.setLabelOffsetType(LengthAdjustmentType.EXPAND);
valuemarker1.setPaint(Color.red);
valuemarker1.setStroke(new BasicStroke(2.0F));
valuemarker1.setLabel("Fitness");
valuemarker1.setLabelFont(new Font("SansSerif", 0, 11));
valuemarker1.setLabelPaint(Color.red);
valuemarker1.setLabelAnchor(RectangleAnchor.TOP_LEFT);
valuemarker1.setLabelTextAnchor(TextAnchor.BOTTOM_LEFT);
plot.addRangeMarker(valuemarker1);
// add the chart to a panel...
ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
//setContentPane(chartPanel);
return chartPanel;
} |
Partager