Java Code Examples for org.jfree.chart.plot.CategoryPlot#setRangeAxis()

The following examples show how to use org.jfree.chart.plot.CategoryPlot#setRangeAxis() . 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: CategoryPlotTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the getRangeAxisIndex() method.
 */
public void testGetRangeAxisIndex() {
    CategoryAxis domainAxis1 = new CategoryAxis("X1");
    NumberAxis rangeAxis1 = new NumberAxis("Y1");
    NumberAxis rangeAxis2 = new NumberAxis("Y2");
    CategoryPlot plot = new CategoryPlot(null, domainAxis1, rangeAxis1, 
            null);
    assertEquals(0, plot.getRangeAxisIndex(rangeAxis1));
    assertEquals(-1, plot.getRangeAxisIndex(rangeAxis2));
    plot.setRangeAxis(1, rangeAxis2);
    assertEquals(1, plot.getRangeAxisIndex(rangeAxis2));
    assertEquals(-1, plot.getRangeAxisIndex(new NumberAxis("Y2")));
    boolean pass = false;
    try {
        plot.getRangeAxisIndex(null);
    }
    catch (IllegalArgumentException e) {
        pass = true;
    }
    assertTrue(pass);
}
 
Example 2
Source File: LogAxisTest.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * A simple test for the auto-range calculation looking at a
 * NumberAxis used as the range axis for a CategoryPlot.  In this
 * case, the original dataset is replaced with a new dataset.
 */
@Test
public void testAutoRange3() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.setValue(100.0, "Row 1", "Column 1");
    dataset.setValue(200.0, "Row 1", "Column 2");
    JFreeChart chart = ChartFactory.createLineChart("Test", "Categories",
            "Value", dataset, PlotOrientation.VERTICAL, false, false,
            false);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    LogAxis axis = new LogAxis("Log(Y)");
    plot.setRangeAxis(axis);
    assertEquals(96.59363289248458, axis.getLowerBound(), EPSILON);
    assertEquals(207.0529847682752, axis.getUpperBound(), EPSILON);

    // now replacing the dataset should update the axis range...
    DefaultCategoryDataset dataset2 = new DefaultCategoryDataset();
    dataset2.setValue(900.0, "Row 1", "Column 1");
    dataset2.setValue(1000.0, "Row 1", "Column 2");
    plot.setDataset(dataset2);
    assertEquals(895.2712433374774, axis.getLowerBound(), EPSILON);
    assertEquals(1005.2819262292991, axis.getUpperBound(), EPSILON);
}
 
Example 3
Source File: LogAxisTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * A simple test for the auto-range calculation looking at a
 * LogAxis used as the range axis for a CategoryPlot.
 */
public void testAutoRange1() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.setValue(100.0, "Row 1", "Column 1");
    dataset.setValue(200.0, "Row 1", "Column 2");
    JFreeChart chart = ChartFactory.createBarChart(
        "Test",
        "Categories",
        "Value",
        dataset,
        PlotOrientation.VERTICAL,
        false,
        false,
        false
    );
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    LogAxis axis = new LogAxis("Log(Y)");
    plot.setRangeAxis(axis);
    assertEquals(0.0, axis.getLowerBound(), EPSILON);
    assertEquals(2.6066426411261268E7, axis.getUpperBound(), EPSILON);
}
 
Example 4
Source File: LogAxisTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * A simple test for the auto-range calculation looking at a
 * NumberAxis used as the range axis for a CategoryPlot.  In this
 * case, the original dataset is replaced with a new dataset.
 */
public void testAutoRange3() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.setValue(100.0, "Row 1", "Column 1");
    dataset.setValue(200.0, "Row 1", "Column 2");
    JFreeChart chart = ChartFactory.createLineChart("Test", "Categories",
            "Value", dataset, PlotOrientation.VERTICAL, false, false,
            false);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    LogAxis axis = new LogAxis("Log(Y)");
    plot.setRangeAxis(axis);
    assertEquals(96.59363289248458, axis.getLowerBound(), EPSILON);
    assertEquals(207.0529847682752, axis.getUpperBound(), EPSILON);

    // now replacing the dataset should update the axis range...
    DefaultCategoryDataset dataset2 = new DefaultCategoryDataset();
    dataset2.setValue(900.0, "Row 1", "Column 1");
    dataset2.setValue(1000.0, "Row 1", "Column 2");
    plot.setDataset(dataset2);
    assertEquals(895.2712433374774, axis.getLowerBound(), EPSILON);
    assertEquals(1005.2819262292991, axis.getUpperBound(), EPSILON);
}
 
Example 5
Source File: LogAxisTest.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * A simple test for the auto-range calculation looking at a
 * NumberAxis used as the range axis for a CategoryPlot.  In this
 * case, the original dataset is replaced with a new dataset.
 */
@Test
public void testAutoRange3() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.setValue(100.0, "Row 1", "Column 1");
    dataset.setValue(200.0, "Row 1", "Column 2");
    JFreeChart chart = ChartFactory.createLineChart("Test", "Categories",
            "Value", dataset, PlotOrientation.VERTICAL, false, false,
            false);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    LogAxis axis = new LogAxis("Log(Y)");
    plot.setRangeAxis(axis);
    assertEquals(96.59363289248458, axis.getLowerBound(), EPSILON);
    assertEquals(207.0529847682752, axis.getUpperBound(), EPSILON);

    // now replacing the dataset should update the axis range...
    DefaultCategoryDataset dataset2 = new DefaultCategoryDataset();
    dataset2.setValue(900.0, "Row 1", "Column 1");
    dataset2.setValue(1000.0, "Row 1", "Column 2");
    plot.setDataset(dataset2);
    assertEquals(895.2712433374774, axis.getLowerBound(), EPSILON);
    assertEquals(1005.2819262292991, axis.getUpperBound(), EPSILON);
}
 
Example 6
Source File: LogAxisTest.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * A simple test for the auto-range calculation looking at a
 * LogAxis used as the range axis for a CategoryPlot.
 */
@Test
public void testAutoRange1() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.setValue(100.0, "Row 1", "Column 1");
    dataset.setValue(200.0, "Row 1", "Column 2");
    JFreeChart chart = ChartFactory.createBarChart("Test", "Categories",
            "Value", dataset);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    LogAxis axis = new LogAxis("Log(Y)");
    plot.setRangeAxis(axis);
    assertEquals(0.0, axis.getLowerBound(), EPSILON);
    assertEquals(2.6066426411261268E7, axis.getUpperBound(), EPSILON);
}
 
Example 7
Source File: CombinedCategoryPlot.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets the range axis that is shared by all the subplots.
 *
 * @param axis  the axis.
 */
public void setRangeAxis(ValueAxis axis) {
    Iterator l_itr = getSubplots().iterator();
    while (l_itr.hasNext()) {
        CategoryPlot l_subplot = (CategoryPlot) l_itr.next();
        l_subplot.setRangeAxis(0, axis, false);
    }

    super.setRangeAxis(axis);
    if (null == axis) {
        return;
    }

    axis.configure();
}
 
Example 8
Source File: CombinedCategoryPlot.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Adds a new subplot with the specified weight.
 *
 * @param subplot  the subplot.
 * @param weight  the weight for the subplot.
 */
public void add(CategoryPlot subplot, int weight) {
    super.add(subplot, weight);

    ValueAxis l_range = super.getRangeAxis();
    subplot.setRangeAxis(0, l_range, false);

    super.setRangeAxis(l_range);
    if (null == l_range) {
        return;
    }

    l_range.configure();
}
 
Example 9
Source File: LogAxisTest.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * A simple test for the auto-range calculation looking at a
 * LogAxis used as the range axis for a CategoryPlot.
 */
@Test
public void testAutoRange1() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.setValue(100.0, "Row 1", "Column 1");
    dataset.setValue(200.0, "Row 1", "Column 2");
    JFreeChart chart = ChartFactory.createBarChart("Test", "Categories",
            "Value", dataset);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    LogAxis axis = new LogAxis("Log(Y)");
    plot.setRangeAxis(axis);
    assertEquals(0.0, axis.getLowerBound(), EPSILON);
    assertEquals(2.6066426411261268E7, axis.getUpperBound(), EPSILON);
}
 
Example 10
Source File: CategoryPlotTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some tests for the getRangeAxisForDataset() method.
 */
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));
}
 
Example 11
Source File: CombinedCategoryPlot.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a new subplot with the specified weight.
 *
 * @param subplot  the subplot.
 * @param weight  the weight for the subplot.
 */
public void add(CategoryPlot subplot, int weight) {
    super.add(subplot, weight);

    ValueAxis l_range = super.getRangeAxis();
    subplot.setRangeAxis(0, l_range, false);

    super.setRangeAxis(l_range);
    if (null == l_range) {
        return;
    }

    l_range.configure();
}
 
Example 12
Source File: CategoryPlotTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * A test for bug report 1169972.
 */
public void test1169972() {
    CategoryPlot plot = new CategoryPlot(null, null, null, null);
    plot.setDomainAxis(new CategoryAxis("C"));
    plot.setRangeAxis(new NumberAxis("Y"));
    plot.setRenderer(new BarRenderer());
    plot.setDataset(new DefaultCategoryDataset());
    assertTrue(plot != null);
}
 
Example 13
Source File: CombinedCategoryPlot.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Adds a new subplot with the specified weight.
 *
 * @param subplot  the subplot.
 * @param weight  the weight for the subplot.
 */
public void add(CategoryPlot subplot, int weight) {
    super.add(subplot, weight);

    ValueAxis l_range = super.getRangeAxis();
    subplot.setRangeAxis(0, l_range, false);

    super.setRangeAxis(l_range);
    if (null == l_range) {
        return;
    }

    l_range.configure();
}
 
Example 14
Source File: CategoryPlotTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * A test for bug report 1169972.
 */
public void test1169972() {
    CategoryPlot plot = new CategoryPlot(null, null, null, null);
    plot.setDomainAxis(new CategoryAxis("C"));
    plot.setRangeAxis(new NumberAxis("Y"));
    plot.setRenderer(new BarRenderer());
    plot.setDataset(new DefaultCategoryDataset());
    assertTrue(plot != null);
}
 
Example 15
Source File: LogAxisTest.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * A simple test for the auto-range calculation looking at a
 * LogAxis used as the range axis for a CategoryPlot.
 */
@Test
public void testAutoRange1() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.setValue(100.0, "Row 1", "Column 1");
    dataset.setValue(200.0, "Row 1", "Column 2");
    JFreeChart chart = ChartFactory.createBarChart("Test", "Categories",
            "Value", dataset);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    LogAxis axis = new LogAxis("Log(Y)");
    plot.setRangeAxis(axis);
    assertEquals(0.0, axis.getLowerBound(), EPSILON);
    assertEquals(2.6066426411261268E7, axis.getUpperBound(), EPSILON);
}
 
Example 16
Source File: LogAxisTest.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * A simple test for the auto-range calculation looking at a
 * LogAxis used as the range axis for a CategoryPlot.
 */
@Test
public void testAutoRange1() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.setValue(100.0, "Row 1", "Column 1");
    dataset.setValue(200.0, "Row 1", "Column 2");
    JFreeChart chart = ChartFactory.createBarChart("Test", "Categories",
            "Value", dataset);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    LogAxis axis = new LogAxis("Log(Y)");
    plot.setRangeAxis(axis);
    assertEquals(0.0, axis.getLowerBound(), EPSILON);
    assertEquals(2.6066426411261268E7, axis.getUpperBound(), EPSILON);
}
 
Example 17
Source File: UserChartController.java    From airsonic-advanced with GNU General Public License v3.0 4 votes vote down vote up
private JFreeChart createChart(CategoryDataset dataset, HttpServletRequest request) {
    JFreeChart chart = ChartFactory.createBarChart(null, null, null, dataset, PlotOrientation.HORIZONTAL, false, false, false);

    CategoryPlot plot = chart.getCategoryPlot();
    Paint background = new GradientPaint(0, 0, Color.lightGray, 0, IMAGE_MIN_HEIGHT, Color.white);
    plot.setBackgroundPaint(background);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    LogarithmicAxis rangeAxis = new LogarithmicAxis(null);
    rangeAxis.setStrictValuesFlag(false);
    rangeAxis.setAllowNegativesFlag(true);
    plot.setRangeAxis(rangeAxis);

    // Disable bar outlines.
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    // Set up gradient paint for series.
    GradientPaint gp0 = new GradientPaint(
            0.0f, 0.0f, Color.blue,
            0.0f, 0.0f, new Color(0, 0, 64)
    );
    renderer.setSeriesPaint(0, gp0);

    // Rotate labels.
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));

    // Set theme-specific colors.
    Color bgColor = getBackground(request);
    Color fgColor = getForeground(request);

    chart.setBackgroundPaint(bgColor);

    domainAxis.setTickLabelPaint(fgColor);
    domainAxis.setTickMarkPaint(fgColor);
    domainAxis.setAxisLinePaint(fgColor);

    rangeAxis.setTickLabelPaint(fgColor);
    rangeAxis.setTickMarkPaint(fgColor);
    rangeAxis.setAxisLinePaint(fgColor);

    return chart;
}
 
Example 18
Source File: CategoricalChartExpressionTest.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
private static CategoryPlot createCategoryPlotWith( ValueAxis rangeAxis ) {
  CategoryPlot plot = new CategoryPlot();
  plot.setRangeAxis( rangeAxis );
  return plot;
}
 
Example 19
Source File: UserChartController.java    From airsonic with GNU General Public License v3.0 4 votes vote down vote up
private JFreeChart createChart(CategoryDataset dataset, HttpServletRequest request) {
    JFreeChart chart = ChartFactory.createBarChart(null, null, null, dataset, PlotOrientation.HORIZONTAL, false, false, false);

    CategoryPlot plot = chart.getCategoryPlot();
    Paint background = new GradientPaint(0, 0, Color.lightGray, 0, IMAGE_MIN_HEIGHT, Color.white);
    plot.setBackgroundPaint(background);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    LogarithmicAxis rangeAxis = new LogarithmicAxis(null);
    rangeAxis.setStrictValuesFlag(false);
    rangeAxis.setAllowNegativesFlag(true);
    plot.setRangeAxis(rangeAxis);

    // Disable bar outlines.
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    // Set up gradient paint for series.
    GradientPaint gp0 = new GradientPaint(
            0.0f, 0.0f, Color.blue,
            0.0f, 0.0f, new Color(0, 0, 64)
    );
    renderer.setSeriesPaint(0, gp0);

    // Rotate labels.
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));

    // Set theme-specific colors.
    Color bgColor = getBackground(request);
    Color fgColor = getForeground(request);

    chart.setBackgroundPaint(bgColor);

    domainAxis.setTickLabelPaint(fgColor);
    domainAxis.setTickMarkPaint(fgColor);
    domainAxis.setAxisLinePaint(fgColor);

    rangeAxis.setTickLabelPaint(fgColor);
    rangeAxis.setTickMarkPaint(fgColor);
    rangeAxis.setAxisLinePaint(fgColor);

    return chart;
}
 
Example 20
Source File: ParetoChartPlotter.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
private JFreeChart createChart() {
	if (data.getItemCount() > 0) {
		// get cumulative percentages
		KeyedValues cumulative = DataUtilities.getCumulativePercentages(data);

		CategoryDataset categoryDataset = DatasetUtilities.createCategoryDataset(
				"Count for " + this.dataTable.getColumnName(this.countColumn) + " = " + countValue, data);

		// create the chart...
		final JFreeChart chart = ChartFactory.createBarChart(null, // chart title
				this.dataTable.getColumnName(this.groupByColumn), // domain axis label
				"Count", // range axis label
				categoryDataset, // data
				PlotOrientation.VERTICAL, true, // include legend
				true, false);

		// set the background color for the chart...
		chart.setBackgroundPaint(Color.WHITE);

		// get a reference to the plot for further customization...
		CategoryPlot plot = chart.getCategoryPlot();

		CategoryAxis domainAxis = plot.getDomainAxis();
		domainAxis.setLowerMargin(0.02);
		domainAxis.setUpperMargin(0.02);
		domainAxis.setLabelFont(LABEL_FONT_BOLD);
		domainAxis.setTickLabelFont(LABEL_FONT);

		// set the range axis to display integers only...
		NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
		rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits(Locale.US));
		rangeAxis.setLabelFont(LABEL_FONT_BOLD);
		rangeAxis.setTickLabelFont(LABEL_FONT);

		// second data set (cumulative percentages)
		CategoryDataset dataset2 = DatasetUtilities.createCategoryDataset("Cumulative (Percent)", cumulative);

		LineAndShapeRenderer renderer2 = new LineAndShapeRenderer();
		renderer2.setSeriesPaint(0, SwingTools.VERY_DARK_BLUE.darker());

		NumberAxis axis2 = new NumberAxis("Percent of " + countValue);
		axis2.setNumberFormatOverride(NumberFormat.getPercentInstance());
		axis2.setLabelFont(LABEL_FONT_BOLD);
		axis2.setTickLabelFont(LABEL_FONT);

		plot.setRangeAxis(1, axis2);
		plot.setDataset(1, dataset2);
		plot.setRenderer(1, renderer2);
		plot.mapDatasetToRangeAxis(1, 1);

		axis2.setTickUnit(new NumberTickUnit(0.1));

		// show grid lines
		plot.setRangeGridlinesVisible(true);

		// bring cumulative line to front
		plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

		if (isLabelRotating()) {
			domainAxis.setTickLabelsVisible(true);
			domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2.0d));
		}

		return chart;
	} else {
		return null;
	}
}