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
| public Graphic(final String title) {
super(title);
final CategoryDataset dataset = createDataset();
final JFreeChart chart = createChart(dataset);
// add the chart to a panel...
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
setContentPane(chartPanel);
}
/**
* Creates a sample dataset.
*
* @return a sample dataset.
*/
private CategoryDataset createDataset() {
final double[][] data = new double[][]
{{0.0},
{0.0},
{0.0},
{0.0},
{0.0}};
/* DefaultCategoryDataset dataset = new DefaultCategoryDataset();
String[] seriesNames = new String[] { "gel douche","brosse","savon","dentifrice","peigne" };
dataset.setSeriesNames(seriesNames);*/
return DatasetUtilities.createCategoryDataset("produits ", " Ma salle de bain ", data);
}
/**
* Creates a chart.
*
* @param dataset the dataset.
*
* @return The chart.
*/
private JFreeChart createChart(final CategoryDataset dataset) {
final JFreeChart chart = ChartFactory.createBarChart3D(
"Mes produits", // chart title
"", // domain axis label
"Nombre", // range axis label
dataset, // data
PlotOrientation.VERTICAL, // orientation
true, // include legend
true, // tooltips
false // urls
);
final CategoryPlot plot = chart.getCategoryPlot();
final CategoryAxis axis = plot.getDomainAxis();
axis.setCategoryLabelPositions(
CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 8.0)
);
final BarRenderer3D renderer = (BarRenderer3D) plot.getRenderer();
renderer.setDrawBarOutline(false);
return chart;
}
} |
Partager