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

The following examples show how to use org.jfree.chart.plot.CategoryPlot#setDomainAxis() . 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: SubCategoryAxisTest.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * A check for the NullPointerException in bug 2275695.
 */
@Test
public void test2275695() {
    JFreeChart chart = ChartFactory.createStackedBarChart("Test",
            "Category", "Value", null, PlotOrientation.VERTICAL,
            true, false, false);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setDomainAxis(new SubCategoryAxis("SubCategoryAxis"));
    try {
        BufferedImage image = new BufferedImage(200 , 100,
                BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = image.createGraphics();
        chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null);
        g2.dispose();
    }
    catch (Exception e) {
        fail("There should be no exception.");
    }
}
 
Example 2
Source File: SubCategoryAxisTest.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * A check for the NullPointerException in bug 2275695.
 */
@Test
public void test2275695() {
    JFreeChart chart = ChartFactory.createStackedBarChart("Test",
            "Category", "Value", null, PlotOrientation.VERTICAL,
            true, false, false);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setDomainAxis(new SubCategoryAxis("SubCategoryAxis"));
    try {
        BufferedImage image = new BufferedImage(200 , 100,
                BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = image.createGraphics();
        chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null);
        g2.dispose();
    }
    catch (Exception e) {
        fail("There should be no exception.");
    }
}
 
Example 3
Source File: SubCategoryAxisTest.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * A check for the NullPointerException in bug 2275695.
 */
@Test
public void test2275695() {
    JFreeChart chart = ChartFactory.createStackedBarChart("Test",
            "Category", "Value", null, PlotOrientation.VERTICAL,
            true, false, false);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setDomainAxis(new SubCategoryAxis("SubCategoryAxis"));
    try {
        BufferedImage image = new BufferedImage(200 , 100,
                BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = image.createGraphics();
        chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null);
        g2.dispose();
    }
    catch (Exception e) {
        fail("There should be no exception.");
    }
}
 
Example 4
Source File: SubCategoryAxisTest.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * A check for the NullPointerException in bug 2275695.
 */
@Test
public void test2275695() {
    JFreeChart chart = ChartFactory.createStackedBarChart("Test",
            "Category", "Value", null, PlotOrientation.VERTICAL,
            true, false, false);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setDomainAxis(new SubCategoryAxis("SubCategoryAxis"));
    try {
        BufferedImage image = new BufferedImage(200 , 100,
                BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = image.createGraphics();
        chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null);
        g2.dispose();
    }
    catch (Exception e) {
        fail("There should be no exception.");
    }
}
 
Example 5
Source File: CategoryPlotTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the getDomainAxisIndex() method.
 */
public void testGetDomainAxisIndex() {
    CategoryAxis domainAxis1 = new CategoryAxis("X1");
    CategoryAxis domainAxis2 = new CategoryAxis("X2");
    NumberAxis rangeAxis1 = new NumberAxis("Y1");
    CategoryPlot plot = new CategoryPlot(null, domainAxis1, rangeAxis1,
            null);
    assertEquals(0, plot.getDomainAxisIndex(domainAxis1));
    assertEquals(-1, plot.getDomainAxisIndex(domainAxis2));
    plot.setDomainAxis(1, domainAxis2);
    assertEquals(1, plot.getDomainAxisIndex(domainAxis2));
    assertEquals(-1, plot.getDomainAxisIndex(new CategoryAxis("X2")));
    boolean pass = false;
    try {
        plot.getDomainAxisIndex(null);
    }
    catch (IllegalArgumentException e) {
        pass = true;
    }
    assertTrue(pass);
}
 
Example 6
Source File: SubCategoryAxisTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * A check for the NullPointerException in bug 2275695.
 */
public void test2275695() {
    JFreeChart chart = ChartFactory.createStackedBarChart("Test",
            "Category", "Value", null, true);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setDomainAxis(new SubCategoryAxis("SubCategoryAxis"));
    boolean success = false;
    try {
        BufferedImage image = new BufferedImage(200 , 100,
                BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = image.createGraphics();
        chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null);
        g2.dispose();
        success = true;
    }
    catch (Exception e) {
        e.printStackTrace();
        success = false;
    }
    assertTrue(success);
}
 
Example 7
Source File: CategoryPlotTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the getDomainAxisIndex() method.
 */
public void testGetDomainAxisIndex() {
    CategoryAxis domainAxis1 = new CategoryAxis("X1");
    CategoryAxis domainAxis2 = new CategoryAxis("X2");
    NumberAxis rangeAxis1 = new NumberAxis("Y1");
    CategoryPlot plot = new CategoryPlot(null, domainAxis1, rangeAxis1, 
            null);
    assertEquals(0, plot.getDomainAxisIndex(domainAxis1));
    assertEquals(-1, plot.getDomainAxisIndex(domainAxis2));
    plot.setDomainAxis(1, domainAxis2);
    assertEquals(1, plot.getDomainAxisIndex(domainAxis2));
    assertEquals(-1, plot.getDomainAxisIndex(new CategoryAxis("X2")));
    boolean pass = false;
    try {
        plot.getDomainAxisIndex(null);
    }
    catch (IllegalArgumentException e) {
        pass = true;
    }
    assertTrue(pass);
}
 
Example 8
Source File: SubCategoryAxisTest.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * A check for the NullPointerException in bug 2275695.
 */
@Test
public void test2275695() {
    JFreeChart chart = ChartFactory.createStackedBarChart("Test",
            "Category", "Value", null, PlotOrientation.VERTICAL,
            true, false, false);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setDomainAxis(new SubCategoryAxis("SubCategoryAxis"));
    try {
        BufferedImage image = new BufferedImage(200 , 100,
                BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = image.createGraphics();
        chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null);
        g2.dispose();
    }
    catch (Exception e) {
        fail("There should be no exception.");
    }
}
 
Example 9
Source File: AWSDeviceFarmGraph.java    From aws-device-farm-jenkins-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Create graph based on the given dataset and constraints.
 *
 * @return The JFreeChart graph.
 */
protected JFreeChart createGraph() {
    // Create chart.
    JFreeChart chart = ChartFactory.createStackedAreaChart(null, null, yLabel, dataset, PlotOrientation.VERTICAL, true, true, false);
    chart.setBackgroundPaint(Color.WHITE);

    // Create chart legend.
    LegendTitle legend = chart.getLegend();
    legend.setPosition(RectangleEdge.RIGHT);

    // Create chart plot.
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setForegroundAlpha(0.7f);
    plot.setBackgroundPaint(Color.WHITE);
    plot.setRangeGridlinePaint(Color.darkGray);

    // Create domain (x) axis.
    CategoryAxis domain = new ShiftedCategoryAxis(xLabel);
    domain.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    domain.setLowerMargin(0.0);
    domain.setUpperMargin(0.0);
    domain.setCategoryMargin(0.0);
    plot.setDomainAxis(domain);

    // Create range (y) axis.
    NumberAxis range = (NumberAxis) plot.getRangeAxis();
    range.setAutoRange(true);
    range.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // Create renderer and paint the chart.
    CategoryItemRenderer renderer = plot.getRenderer();
    plot.setInsets(new RectangleInsets(5.0, 0, 0, 5.0));

    // Set chart colors for sections.
    for (int i = 0; i < colors.length; i++) {
        renderer.setSeriesPaint(i, colors[i]);
    }
    return chart;
}
 
Example 10
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 11
Source File: CategoryPlotTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some tests for the getDomainAxisForDataset() method.
 */
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));
}
 
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: LineChart.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
public JFreeChart createChart(){
	
	logger.debug("IN");
	CategoryPlot plot = new CategoryPlot();

	
	NumberAxis rangeAxis = new NumberAxis("Kpi Values");
	rangeAxis.setLabelFont(new Font("Arial", Font.PLAIN, 12 ));
	Color colorLabel= Color.decode("#000000");
	rangeAxis.setLabelPaint(colorLabel);
	rangeAxis.setTickLabelFont(new Font("Arial", Font.PLAIN, 10 ));
	rangeAxis.setTickLabelPaint(colorLabel);
	plot.setRangeAxis(rangeAxis);
	
	CategoryAxis domainAxis = new CategoryAxis();
	domainAxis.setLabelFont(new Font("Arial", Font.PLAIN, 10 ));
       domainAxis.setLabelPaint(colorLabel);
       domainAxis.setTickLabelFont(new Font("Arial", Font.PLAIN, 10 ));
       domainAxis.setTickLabelPaint(colorLabel);
	plot.setDomainAxis(domainAxis);

	plot.setOrientation(PlotOrientation.VERTICAL);
	plot.setRangeGridlinesVisible(true);
	plot.setDomainGridlinesVisible(true);


	//I create a line renderer 
	MyStandardCategoryItemLabelGenerator generator=null;

		LineAndShapeRenderer lineRenderer = new LineAndShapeRenderer();
		lineRenderer.setShapesFilled(true);
		lineRenderer.setBaseItemLabelGenerator(generator);
		lineRenderer.setBaseItemLabelFont(new Font("Arial", Font.PLAIN, 12 ));
		lineRenderer.setBaseItemLabelPaint(colorLabel);
		lineRenderer.setBaseItemLabelsVisible(true);

		DefaultCategoryDataset datasetLine=(DefaultCategoryDataset)datasetMap.getDatasets().get("line");

			for (Iterator iterator = datasetLine.getRowKeys().iterator(); iterator.hasNext();) {
				String serName = (String) iterator.next();
				String labelName = "";
				int index=-1;
				index=datasetLine.getRowIndex(serName);
				
				Color color=Color.decode("#990200");
				lineRenderer.setSeriesPaint(index, color);	
			}

		plot.setDataset(0,datasetLine);
		plot.setRenderer(0,lineRenderer);

	plot.getDomainAxis().setCategoryLabelPositions(
			CategoryLabelPositions.UP_45);
	JFreeChart chart = new JFreeChart(plot);
	logger.debug("Chart created");
	TextTitle title=new TextTitle(name,new Font("Arial", Font.BOLD, 16 ),Color.decode("#990200"), RectangleEdge.TOP, HorizontalAlignment.CENTER, VerticalAlignment.TOP, RectangleInsets.ZERO_INSETS);
	chart.setTitle(title);
	TextTitle subTitle =new TextTitle(subName,new Font("Arial", Font.PLAIN, 12 ),Color.decode("#000000"), RectangleEdge.TOP, HorizontalAlignment.CENTER, VerticalAlignment.TOP, RectangleInsets.ZERO_INSETS);
	chart.addSubtitle(subTitle);
	TextTitle subTitle2 =new TextTitle(subName,new Font("Arial", Font.PLAIN, 8 ),Color.decode("#FFFFFF"), RectangleEdge.TOP, HorizontalAlignment.CENTER, VerticalAlignment.TOP, RectangleInsets.ZERO_INSETS);
	chart.addSubtitle(subTitle2);
	chart.removeLegend();
	
	chart.setBackgroundPaint(Color.white);
	logger.debug("OUT");
	return chart;
}
 
Example 14
Source File: ChartJFreeChartOutputHistogram.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
public void resetDomainAxis(final IScope scope) {
	// TODO Auto-generated method stub
	final CategoryPlot pp = (CategoryPlot) chart.getPlot();
	if (this.useSubAxis) {
		final SubCategoryAxis newAxis = new SubCategoryAxis(pp.getDomainAxis().getLabel());
		pp.setDomainAxis(newAxis);
	}

	pp.getDomainAxis().setAxisLinePaint(axesColor);
	pp.getDomainAxis().setTickLabelFont(getTickFont());
	pp.getDomainAxis().setLabelFont(getLabelFont());
	if (textColor != null) {
		pp.getDomainAxis().setLabelPaint(textColor);
		pp.getDomainAxis().setTickLabelPaint(textColor);
		if (this.series_label_position.equals("xaxis")) {
			((SubCategoryAxis)pp.getDomainAxis()).setSubLabelPaint(textColor);
		}			
	}

	if (gap > 0) {

		pp.getDomainAxis().setCategoryMargin(gap);
		pp.getDomainAxis().setUpperMargin(gap);
		pp.getDomainAxis().setLowerMargin(gap);
	}

	if (this.useSubAxis && !this.useMainAxisLabel) {
		pp.getDomainAxis().setTickLabelsVisible(false);
		// pp.getDomainAxis().setTickLabelPaint(this.backgroundColor);
		// pp.getDomainAxis().setLabelFont(new Font(labelFontFace,
		// labelFontStyle, 1));
	}
	if (!this.getYTickLineVisible(scope)) {
		pp.setDomainGridlinesVisible(false);
	}

	if (!this.getYTickLineVisible(scope)) {
		pp.setRangeCrosshairVisible(false);

	}

	if (!this.getYTickValueVisible(scope)) {
		pp.getRangeAxis().setTickMarksVisible(false);
		pp.getRangeAxis().setTickLabelsVisible(false);

	}
	if (!this.getXTickValueVisible(scope)) {
		pp.getDomainAxis().setTickMarksVisible(false);
		pp.getDomainAxis().setTickLabelsVisible(false);

	}

}