Example usage for org.jfree.data.category DefaultIntervalCategoryDataset setCategoryKeys

List of usage examples for org.jfree.data.category DefaultIntervalCategoryDataset setCategoryKeys

Introduction

In this page you can find the example usage for org.jfree.data.category DefaultIntervalCategoryDataset setCategoryKeys.

Prototype

public void setCategoryKeys(Comparable[] categoryKeys) 

Source Link

Document

Sets the categories for the dataset.

Usage

From source file:org.jfree.chart.demo.IntervalBarChartDemo1.java

/**
 * Creates a new demo.//www. j a  v a  2 s.co  m
 */
public IntervalBarChartDemo1() {

    DefaultIntervalCategoryDataset data = null;
    final double[][] lows = { { -.0315, .0159, .0306, .0453, .0557 } };
    final double[][] highs = { { .1931, .1457, .1310, .1163, .1059 } };
    data = new DefaultIntervalCategoryDataset(lows, highs);
    data.setCategoryKeys(CATEGORIES);

    final String title = "Strategie Sicherheit";
    final String xTitle = "Zeitraum (in Jahren)";
    final String yTitle = "Performance";
    final CategoryAxis xAxis = new CategoryAxis(xTitle);
    xAxis.setLabelFont(titleFont);
    xAxis.setTickLabelFont(labelFont);
    xAxis.setTickMarksVisible(false);
    final NumberAxis yAxis = new NumberAxis(yTitle);
    yAxis.setLabelFont(titleFont);
    yAxis.setTickLabelFont(labelFont);
    yAxis.setRange(-0.2, 0.40);
    final DecimalFormat formatter = new DecimalFormat("0.##%");
    yAxis.setTickUnit(new NumberTickUnit(0.05, formatter));

    final IntervalBarRenderer renderer = new IntervalBarRenderer();
    renderer.setSeriesPaint(0, new Color(51, 102, 153));
    //        renderer.setLabelGenerator(new IntervalCategoryLabelGenerator());
    renderer.setItemLabelsVisible(true);
    renderer.setItemLabelPaint(Color.white);
    final ItemLabelPosition p = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER);
    renderer.setPositiveItemLabelPosition(p);

    final CategoryPlot plot = new CategoryPlot(data, xAxis, yAxis, renderer);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setOutlinePaint(Color.white);
    plot.setOrientation(PlotOrientation.VERTICAL);

    this.chart = new JFreeChart(title, titleFont, plot, false);
    this.chart.setBackgroundPaint(Color.white);
}

From source file:org.jfree.data.category.DefaultIntervalCategoryDatasetTest.java

/**
 * Some checks for the setCategoryKeys() method.
 *///from w ww . j  a  va  2 s  . c  o m
@Test
public void testSetCategoryKeys() {
    // check an empty dataset
    DefaultIntervalCategoryDataset empty = new DefaultIntervalCategoryDataset(new double[0][0],
            new double[0][0]);
    boolean pass = true;
    try {
        empty.setCategoryKeys(new String[0]);
    } catch (RuntimeException e) {
        pass = false;
    }
    assertTrue(pass);
}