Java Code Examples for org.jfree.chart.renderer.category.BarRenderer#setBasePositiveItemLabelPosition()

The following examples show how to use org.jfree.chart.renderer.category.BarRenderer#setBasePositiveItemLabelPosition() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChartFactory.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a bar chart.  The chart object returned by this method uses a
 * {@link CategoryPlot} instance as the plot, with a {@link CategoryAxis}
 * for the domain axis, a {@link NumberAxis} as the range axis, and a
 * {@link BarRenderer} as the renderer.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param categoryAxisLabel  the label for the category axis
 *                           (<code>null</code> permitted).
 * @param valueAxisLabel  the label for the value axis
 *                        (<code>null</code> permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 *
 * @return A bar chart.
 */
public static JFreeChart createBarChart(String title,
        String categoryAxisLabel, String valueAxisLabel,
        CategoryDataset dataset, boolean legend) {

    CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
    ValueAxis valueAxis = new NumberAxis(valueAxisLabel);
    BarRenderer renderer = new BarRenderer();
    ItemLabelPosition position1 = new ItemLabelPosition(
            ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER);
    renderer.setBasePositiveItemLabelPosition(position1);
    ItemLabelPosition position2 = new ItemLabelPosition(
            ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_CENTER);
    renderer.setBaseNegativeItemLabelPosition(position2);
    renderer.setBaseToolTipGenerator(
            new StandardCategoryToolTipGenerator());
    CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis,
            renderer);
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
            plot, legend);
    currentTheme.apply(chart);
    return chart;

}
 
Example 2
Source File: Histogram.java    From chipster with MIT License 5 votes vote down vote up
private void updateHistogram() throws MicroarrayException, IOException {

		updateChipBox();

		int barCount = ((SpinnerNumberModel) barCountSpinner.getModel()).getNumber().intValue();
		String expression = ((Variable) chipBox.getSelectedItem()).getExpression();
		FloatArrayList histogram = getHistogram(barCount, expression);

		if (histogram != null) {
			CategoryDataset dataset = toCategoryDataset(histogram);

			CategoryAxis categoryAxis = new CategoryAxis("value");
			ValueAxis valueAxis = new NumberAxis("count");

			BarRenderer renderer = new BarRenderer();
			ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER);
			renderer.setBasePositiveItemLabelPosition(position1);
			ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_CENTER);
			renderer.setBaseNegativeItemLabelPosition(position2);

			CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer);
			plot.setOrientation(PlotOrientation.VERTICAL);
			JFreeChart chart = new JFreeChart(data.getName(), JFreeChart.DEFAULT_TITLE_FONT, plot, false);

			visualisationPanel.removeAll();
			visualisationPanel.add(makePanel(chart), BorderLayout.CENTER);
			visualisationPanel.validate();

		} else {
			throw new IllegalArgumentException("histogram not supported for " + data.getName());
		}

	}