Search in sources :

Example 66 with NumberAxis

use of org.jfree.chart.axis.NumberAxis in project SIMVA-SoS by SESoS.

the class CategoryPlotTest method testGetDomainAxisForDataset.

/**
 * Some tests for the getDomainAxisForDataset() method.
 */
@Test
public void testGetDomainAxisForDataset() {
    CategoryDataset dataset = new DefaultCategoryDataset();
    CategoryAxis xAxis = new CategoryAxis("X");
    NumberAxis yAxis = new NumberAxis("Y");
    CategoryItemRenderer renderer = new BarRenderer();
    CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
    assertEquals(xAxis, plot.getDomainAxisForDataset(0));
    // should get IllegalArgumentException for negative index
    boolean pass = false;
    try {
        plot.getDomainAxisForDataset(-1);
    } catch (IllegalArgumentException e) {
        pass = true;
    }
    assertTrue(pass);
    // if multiple axes are mapped, the first in the list should be
    // returned...
    CategoryAxis xAxis2 = new CategoryAxis("X2");
    plot.setDomainAxis(1, xAxis2);
    assertEquals(xAxis, plot.getDomainAxisForDataset(0));
    plot.mapDatasetToDomainAxis(0, 1);
    assertEquals(xAxis2, plot.getDomainAxisForDataset(0));
    List axisIndices = Arrays.asList(new Integer[] { new Integer(0), new Integer(1) });
    plot.mapDatasetToDomainAxes(0, axisIndices);
    assertEquals(xAxis, plot.getDomainAxisForDataset(0));
    axisIndices = Arrays.asList(new Integer[] { new Integer(1), new Integer(2) });
    plot.mapDatasetToDomainAxes(0, axisIndices);
    assertEquals(xAxis2, plot.getDomainAxisForDataset(0));
}
Also used : NumberAxis(org.jfree.chart.axis.NumberAxis) DefaultCategoryItemRenderer(org.jfree.chart.renderer.category.DefaultCategoryItemRenderer) CategoryItemRenderer(org.jfree.chart.renderer.category.CategoryItemRenderer) CategoryAxis(org.jfree.chart.axis.CategoryAxis) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) CategoryDataset(org.jfree.data.category.CategoryDataset) BarRenderer(org.jfree.chart.renderer.category.BarRenderer) List(java.util.List) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) Test(org.junit.Test)

Example 67 with NumberAxis

use of org.jfree.chart.axis.NumberAxis in project SIMVA-SoS by SESoS.

the class CategoryPlotTest method testGetRangeAxisForDataset.

/**
 * Some tests for the getRangeAxisForDataset() method.
 */
@Test
public void testGetRangeAxisForDataset() {
    CategoryDataset dataset = new DefaultCategoryDataset();
    CategoryAxis xAxis = new CategoryAxis("X");
    NumberAxis yAxis = new NumberAxis("Y");
    CategoryItemRenderer renderer = new DefaultCategoryItemRenderer();
    CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
    assertEquals(yAxis, plot.getRangeAxisForDataset(0));
    // should get IllegalArgumentException for negative index
    boolean pass = false;
    try {
        plot.getRangeAxisForDataset(-1);
    } catch (IllegalArgumentException e) {
        pass = true;
    }
    assertTrue(pass);
    // if multiple axes are mapped, the first in the list should be
    // returned...
    NumberAxis yAxis2 = new NumberAxis("Y2");
    plot.setRangeAxis(1, yAxis2);
    assertEquals(yAxis, plot.getRangeAxisForDataset(0));
    plot.mapDatasetToRangeAxis(0, 1);
    assertEquals(yAxis2, plot.getRangeAxisForDataset(0));
    List axisIndices = Arrays.asList(new Integer[] { new Integer(0), new Integer(1) });
    plot.mapDatasetToRangeAxes(0, axisIndices);
    assertEquals(yAxis, plot.getRangeAxisForDataset(0));
    axisIndices = Arrays.asList(new Integer[] { new Integer(1), new Integer(2) });
    plot.mapDatasetToRangeAxes(0, axisIndices);
    assertEquals(yAxis2, plot.getRangeAxisForDataset(0));
}
Also used : NumberAxis(org.jfree.chart.axis.NumberAxis) DefaultCategoryItemRenderer(org.jfree.chart.renderer.category.DefaultCategoryItemRenderer) CategoryItemRenderer(org.jfree.chart.renderer.category.CategoryItemRenderer) DefaultCategoryItemRenderer(org.jfree.chart.renderer.category.DefaultCategoryItemRenderer) CategoryAxis(org.jfree.chart.axis.CategoryAxis) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) CategoryDataset(org.jfree.data.category.CategoryDataset) List(java.util.List) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) Test(org.junit.Test)

Example 68 with NumberAxis

use of org.jfree.chart.axis.NumberAxis in project SIMVA-SoS by SESoS.

the class CategoryPlotTest method testGetRendererForDataset2.

@Test
public void testGetRendererForDataset2() {
    CategoryDataset dataset = new DefaultCategoryDataset();
    CategoryAxis xAxis = new CategoryAxis("X");
    NumberAxis yAxis = new NumberAxis("Y");
    CategoryItemRenderer renderer = new BarRenderer();
    CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
    // add a second dataset
    DefaultCategoryDataset dataset2 = new DefaultCategoryDataset();
    dataset2.setValue(1, "R1", "C1");
    plot.setDataset(99, dataset2);
    // by default, the renderer with index 0 is used
    assertEquals(renderer, plot.getRendererForDataset(dataset2));
    // add a second renderer with the same index as dataset2, now it will
    // be used
    CategoryItemRenderer renderer2 = new LineAndShapeRenderer();
    plot.setRenderer(99, renderer2);
    assertEquals(renderer2, plot.getRendererForDataset(dataset2));
}
Also used : LineAndShapeRenderer(org.jfree.chart.renderer.category.LineAndShapeRenderer) NumberAxis(org.jfree.chart.axis.NumberAxis) DefaultCategoryItemRenderer(org.jfree.chart.renderer.category.DefaultCategoryItemRenderer) CategoryItemRenderer(org.jfree.chart.renderer.category.CategoryItemRenderer) CategoryAxis(org.jfree.chart.axis.CategoryAxis) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) CategoryDataset(org.jfree.data.category.CategoryDataset) BarRenderer(org.jfree.chart.renderer.category.BarRenderer) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) Test(org.junit.Test)

Example 69 with NumberAxis

use of org.jfree.chart.axis.NumberAxis in project SIMVA-SoS by SESoS.

the class CategoryPlotTest method testDatasetIndices.

/**
 * Datasets are now stored in a Map, and it should be possible to assign
 * them an arbitrary key (index).
 */
@Test
public void testDatasetIndices() {
    CategoryDataset dataset = new DefaultCategoryDataset();
    CategoryAxis xAxis = new CategoryAxis("X");
    NumberAxis yAxis = new NumberAxis("Y");
    CategoryItemRenderer renderer = new BarRenderer();
    CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
    assertEquals(dataset, plot.getDataset(0));
    DefaultCategoryDataset dataset2 = new DefaultCategoryDataset();
    dataset2.setValue(1, "R1", "C1");
    // we should be able to give a dataset an arbitrary index
    plot.setDataset(99, dataset2);
    assertEquals(2, plot.getDatasetCount());
    assertEquals(dataset2, plot.getDataset(99));
    assertEquals(0, plot.indexOf(dataset));
    assertEquals(99, plot.indexOf(dataset2));
}
Also used : NumberAxis(org.jfree.chart.axis.NumberAxis) DefaultCategoryItemRenderer(org.jfree.chart.renderer.category.DefaultCategoryItemRenderer) CategoryItemRenderer(org.jfree.chart.renderer.category.CategoryItemRenderer) CategoryAxis(org.jfree.chart.axis.CategoryAxis) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) CategoryDataset(org.jfree.data.category.CategoryDataset) BarRenderer(org.jfree.chart.renderer.category.BarRenderer) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) Test(org.junit.Test)

Example 70 with NumberAxis

use of org.jfree.chart.axis.NumberAxis in project SIMVA-SoS by SESoS.

the class CombinedDomainCategoryPlotTest method createPlot.

/**
 * Creates a sample plot.
 *
 * @return A sample plot.
 */
private CombinedDomainCategoryPlot createPlot() {
    CategoryDataset dataset1 = createDataset1();
    NumberAxis rangeAxis1 = new NumberAxis("Value");
    rangeAxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    LineAndShapeRenderer renderer1 = new LineAndShapeRenderer();
    renderer1.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    CategoryPlot subplot1 = new CategoryPlot(dataset1, null, rangeAxis1, renderer1);
    subplot1.setDomainGridlinesVisible(true);
    CategoryDataset dataset2 = createDataset2();
    NumberAxis rangeAxis2 = new NumberAxis("Value");
    rangeAxis2.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    BarRenderer renderer2 = new BarRenderer();
    renderer2.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    CategoryPlot subplot2 = new CategoryPlot(dataset2, null, rangeAxis2, renderer2);
    subplot2.setDomainGridlinesVisible(true);
    CategoryAxis domainAxis = new CategoryAxis("Category");
    CombinedDomainCategoryPlot plot = new CombinedDomainCategoryPlot(domainAxis);
    plot.add(subplot1, 2);
    plot.add(subplot2, 1);
    return plot;
}
Also used : LineAndShapeRenderer(org.jfree.chart.renderer.category.LineAndShapeRenderer) NumberAxis(org.jfree.chart.axis.NumberAxis) CategoryAxis(org.jfree.chart.axis.CategoryAxis) StandardCategoryToolTipGenerator(org.jfree.chart.labels.StandardCategoryToolTipGenerator) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) CategoryDataset(org.jfree.data.category.CategoryDataset) BarRenderer(org.jfree.chart.renderer.category.BarRenderer)

Aggregations

NumberAxis (org.jfree.chart.axis.NumberAxis)259 JFreeChart (org.jfree.chart.JFreeChart)146 Test (org.junit.Test)118 XYPlot (org.jfree.chart.plot.XYPlot)98 CategoryAxis (org.jfree.chart.axis.CategoryAxis)95 CategoryPlot (org.jfree.chart.plot.CategoryPlot)80 ValueAxis (org.jfree.chart.axis.ValueAxis)45 DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)44 XYLineAndShapeRenderer (org.jfree.chart.renderer.xy.XYLineAndShapeRenderer)40 XYSeriesCollection (org.jfree.data.xy.XYSeriesCollection)39 XYSeries (org.jfree.data.xy.XYSeries)38 BarRenderer (org.jfree.chart.renderer.category.BarRenderer)37 XYItemRenderer (org.jfree.chart.renderer.xy.XYItemRenderer)30 XYDataset (org.jfree.data.xy.XYDataset)30 Color (java.awt.Color)28 DateAxis (org.jfree.chart.axis.DateAxis)27 StandardXYToolTipGenerator (org.jfree.chart.labels.StandardXYToolTipGenerator)27 BasicStroke (java.awt.BasicStroke)25 StandardXYItemRenderer (org.jfree.chart.renderer.xy.StandardXYItemRenderer)24 CategoryDataset (org.jfree.data.category.CategoryDataset)21