org.jfree.chart.axis.SubCategoryAxis Java Examples

The following examples show how to use org.jfree.chart.axis.SubCategoryAxis. 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: 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 #2
Source File: StandardChartTheme.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Applies the attributes for this theme to a {@link CategoryAxis}.
 *
 * @param axis  the axis (<code>null</code> not permitted).
 */
protected void applyToCategoryAxis(CategoryAxis axis) {
    axis.setLabelFont(this.largeFont);
    axis.setLabelPaint(this.axisLabelPaint);
    axis.setTickLabelFont(this.regularFont);
    axis.setTickLabelPaint(this.tickLabelPaint);
    if (axis instanceof SubCategoryAxis) {
        SubCategoryAxis sca = (SubCategoryAxis) axis;
        sca.setSubLabelFont(this.regularFont);
        sca.setSubLabelPaint(this.tickLabelPaint);
    }
}
 
Example #3
Source File: StandardChartTheme.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Applies the attributes for this theme to a {@link CategoryAxis}.
 *
 * @param axis  the axis (<code>null</code> not permitted).
 */
protected void applyToCategoryAxis(CategoryAxis axis) {
    axis.setLabelFont(this.largeFont);
    axis.setLabelPaint(this.axisLabelPaint);
    axis.setTickLabelFont(this.regularFont);
    axis.setTickLabelPaint(this.tickLabelPaint);
    if (axis instanceof SubCategoryAxis) {
        SubCategoryAxis sca = (SubCategoryAxis) axis;
        sca.setSubLabelFont(this.regularFont);
        sca.setSubLabelPaint(this.tickLabelPaint);
    }
}
 
Example #4
Source File: StandardChartTheme.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Applies the attributes for this theme to a {@link CategoryAxis}.
 *
 * @param axis  the axis (<code>null</code> not permitted).
 */
protected void applyToCategoryAxis(CategoryAxis axis) {
    axis.setLabelFont(this.largeFont);
    axis.setLabelPaint(this.axisLabelPaint);
    axis.setTickLabelFont(this.regularFont);
    axis.setTickLabelPaint(this.tickLabelPaint);
    if (axis instanceof SubCategoryAxis) {
        SubCategoryAxis sca = (SubCategoryAxis) axis;
        sca.setSubLabelFont(this.regularFont);
        sca.setSubLabelPaint(this.tickLabelPaint);
    }
}
 
Example #5
Source File: StandardChartTheme.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Applies the attributes for this theme to a {@link CategoryAxis}.
 *
 * @param axis  the axis (<code>null</code> not permitted).
 */
protected void applyToCategoryAxis(CategoryAxis axis) {
    axis.setLabelFont(this.largeFont);
    axis.setLabelPaint(this.axisLabelPaint);
    axis.setTickLabelFont(this.regularFont);
    axis.setTickLabelPaint(this.tickLabelPaint);
    if (axis instanceof SubCategoryAxis) {
        SubCategoryAxis sca = (SubCategoryAxis) axis;
        sca.setSubLabelFont(this.regularFont);
        sca.setSubLabelPaint(this.tickLabelPaint);
    }
}
 
Example #6
Source File: SubCategoryAxisTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Confirm that the equals method can distinguish all the required fields.
 */
public void testEquals() {

    SubCategoryAxis a1 = new SubCategoryAxis("Test");
    SubCategoryAxis a2 = new SubCategoryAxis("Test");
    assertTrue(a1.equals(a2));
    assertTrue(a2.equals(a1));

    // subcategories
    a1.addSubCategory("Sub 1");
    assertFalse(a1.equals(a2));
    a2.addSubCategory("Sub 1");
    assertTrue(a1.equals(a2));

    // subLabelFont
    a1.setSubLabelFont(new Font("Serif", Font.BOLD, 15));
    assertFalse(a1.equals(a2));
    a2.setSubLabelFont(new Font("Serif", Font.BOLD, 15));
    assertTrue(a1.equals(a2));

    // subLabelPaint
    a1.setSubLabelPaint(Color.red);
    assertFalse(a1.equals(a2));
    a2.setSubLabelPaint(Color.red);
    assertTrue(a1.equals(a2));

}
 
Example #7
Source File: SubCategoryAxisTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Two objects that are equal are required to return the same hashCode.
 */
public void testHashCode() {
    SubCategoryAxis a1 = new SubCategoryAxis("Test");
    SubCategoryAxis a2 = new SubCategoryAxis("Test");
    assertTrue(a1.equals(a2));
    int h1 = a1.hashCode();
    int h2 = a2.hashCode();
    assertEquals(h1, h2);
}
 
Example #8
Source File: StandardChartTheme.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Applies the attributes for this theme to a {@link CategoryAxis}.
 *
 * @param axis  the axis (<code>null</code> not permitted).
 */
protected void applyToCategoryAxis(CategoryAxis axis) {
    axis.setLabelFont(this.largeFont);
    axis.setLabelPaint(this.axisLabelPaint);
    axis.setTickLabelFont(this.regularFont);
    axis.setTickLabelPaint(this.tickLabelPaint);
    if (axis instanceof SubCategoryAxis) {
        SubCategoryAxis sca = (SubCategoryAxis) axis;
        sca.setSubLabelFont(this.regularFont);
        sca.setSubLabelPaint(this.tickLabelPaint);
    }
}
 
Example #9
Source File: SubCategoryAxisTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Confirm that the equals method can distinguish all the required fields.
 */
public void testEquals() {
    
    SubCategoryAxis a1 = new SubCategoryAxis("Test");
    SubCategoryAxis a2 = new SubCategoryAxis("Test");
    assertTrue(a1.equals(a2));
    assertTrue(a2.equals(a1));
    
    // subcategories
    a1.addSubCategory("Sub 1");
    assertFalse(a1.equals(a2));
    a2.addSubCategory("Sub 1");
    assertTrue(a1.equals(a2));

    // subLabelFont 
    a1.setSubLabelFont(new Font("Serif", Font.BOLD, 15));
    assertFalse(a1.equals(a2));
    a2.setSubLabelFont(new Font("Serif", Font.BOLD, 15));
    assertTrue(a1.equals(a2));
  
    // subLabelPaint 
    a1.setSubLabelPaint(Color.red);
    assertFalse(a1.equals(a2));
    a2.setSubLabelPaint(Color.red);
    assertTrue(a1.equals(a2));
            
}
 
Example #10
Source File: SubCategoryAxisTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Two objects that are equal are required to return the same hashCode. 
 */
public void testHashCode() {
    SubCategoryAxis a1 = new SubCategoryAxis("Test");
    SubCategoryAxis a2 = new SubCategoryAxis("Test");
    assertTrue(a1.equals(a2));
    int h1 = a1.hashCode();
    int h2 = a2.hashCode();
    assertEquals(h1, h2);
}
 
Example #11
Source File: StandardChartTheme.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Applies the attributes for this theme to a {@link CategoryAxis}.
 *
 * @param axis  the axis (<code>null</code> not permitted).
 */
protected void applyToCategoryAxis(CategoryAxis axis) {
    axis.setLabelFont(this.largeFont);
    axis.setLabelPaint(this.axisLabelPaint);
    axis.setTickLabelFont(this.regularFont);
    axis.setTickLabelPaint(this.tickLabelPaint);
    if (axis instanceof SubCategoryAxis) {
        SubCategoryAxis sca = (SubCategoryAxis) axis;
        sca.setSubLabelFont(this.regularFont);
        sca.setSubLabelPaint(this.tickLabelPaint);
    }
}
 
Example #12
Source File: StandardChartTheme.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Applies the attributes for this theme to a {@link CategoryAxis}.
 *
 * @param axis  the axis (<code>null</code> not permitted).
 */
protected void applyToCategoryAxis(CategoryAxis axis) {
    axis.setLabelFont(this.largeFont);
    axis.setLabelPaint(this.axisLabelPaint);
    axis.setTickLabelFont(this.regularFont);
    axis.setTickLabelPaint(this.tickLabelPaint);
    if (axis instanceof SubCategoryAxis) {
        SubCategoryAxis sca = (SubCategoryAxis) axis;
        sca.setSubLabelFont(this.regularFont);
        sca.setSubLabelPaint(this.tickLabelPaint);
    }
}
 
Example #13
Source File: ChartJFreeChartOutputHistogram.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void resetAxes(final IScope scope) {
	final CategoryPlot pp = (CategoryPlot) this.chart.getPlot();
	NumberAxis rangeAxis = (NumberAxis) ((CategoryPlot) this.chart.getPlot()).getRangeAxis();
	if (getY_LogScale(scope)) {
		final LogarithmicAxis logAxis = new LogarithmicAxis(rangeAxis.getLabel());
		logAxis.setAllowNegativesFlag(true);
		((CategoryPlot) this.chart.getPlot()).setRangeAxis(logAxis);
		rangeAxis = logAxis;
	}

	if (!useyrangeinterval && !useyrangeminmax) {
		rangeAxis.setAutoRange(true);
	}

	if (this.useyrangeinterval) {
		rangeAxis.setFixedAutoRange(yrangeinterval);
		rangeAxis.setAutoRangeMinimumSize(yrangeinterval);
		rangeAxis.setAutoRange(true);

	}
	if (this.useyrangeminmax) {
		rangeAxis.setRange(yrangemin, yrangemax);

	}

	resetDomainAxis(scope);

	final CategoryAxis domainAxis = ((CategoryPlot) this.chart.getPlot()).getDomainAxis();

	pp.setDomainGridlinePaint(axesColor);
	pp.setRangeGridlinePaint(axesColor);
	pp.setRangeCrosshairVisible(true);

	pp.getRangeAxis().setAxisLinePaint(axesColor);
	pp.getRangeAxis().setLabelFont(getLabelFont());
	pp.getRangeAxis().setTickLabelFont(getTickFont());
	if (textColor != null) {
		pp.getRangeAxis().setLabelPaint(textColor);
		pp.getRangeAxis().setTickLabelPaint(textColor);
	}
	if (getYTickUnit(scope) > 0) {
		((NumberAxis) pp.getRangeAxis()).setTickUnit(new NumberTickUnit(getYTickUnit(scope)));
	}

	if (getYLabel(scope) != null && !getYLabel(scope).isEmpty()) {
		pp.getRangeAxis().setLabel(getYLabel(scope));
	}
	if (this.series_label_position.equals("yaxis")) {
		pp.getRangeAxis().setLabel(this.getChartdataset().getDataSeriesIds(scope).iterator().next());
		chart.getLegend().setVisible(false);
	}

	if (getXLabel(scope) != null && !getXLabel(scope).isEmpty()) {
		pp.getDomainAxis().setLabel(getXLabel(scope));
	}

	if (this.useSubAxis) {
		for (final String serieid : chartdataset.getDataSeriesIds(scope)) {
			((SubCategoryAxis) domainAxis).addSubCategory(serieid);
		}

	}
	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);

	}

}
 
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);

	}

}
 
Example #15
Source File: ChartJFreeChartOutputHistogram.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void initChart_post_data_init(final IScope scope) {
	// TODO Auto-generated method stub
	super.initChart_post_data_init(scope);
	final CategoryPlot pp = (CategoryPlot) chart.getPlot();

	final String sty = getStyle();
	this.useSubAxis = false;
	switch (sty) {
		case IKeyword.STACK: {
			if (this.series_label_position.equals("xaxis")) {
				this.series_label_position = "default";
			}
			if (this.series_label_position.equals("default")) {
				this.series_label_position = "legend";
			}
			break;
		}
		default: {
			if (this.series_label_position.equals("default")) {
				if (this.getChartdataset().getSources().size() > 0) {
					final ChartDataSource onesource = this.getChartdataset().getSources().get(0);
					if (onesource.isCumulative) {
						this.series_label_position = "legend";
					} else {
						this.series_label_position = "xaxis";
						useMainAxisLabel = false;
					}

				} else {
					this.series_label_position = "legend";

				}
			}
			break;
		}
	}
	if (this.series_label_position.equals("xaxis")) {
		this.useSubAxis = true;
	}

	if (!this.series_label_position.equals("legend")) {
		chart.getLegend().setVisible(false);
		// legend is useless, but I find it nice anyway... Could put back...
	}
	this.resetDomainAxis(scope);

	pp.setDomainGridlinePaint(axesColor);
	pp.setRangeGridlinePaint(axesColor);
	if (!this.getXTickLineVisible(scope)) {
		pp.setDomainGridlinesVisible(false);
	}
	if (!this.getYTickLineVisible(scope)) {
		pp.setRangeGridlinesVisible(false);
	}
	pp.setRangeCrosshairVisible(true);
	pp.getRangeAxis().setAxisLinePaint(axesColor);
	pp.getRangeAxis().setLabelFont(getLabelFont());
	pp.getRangeAxis().setTickLabelFont(getTickFont());
	if (textColor != null) {
		pp.getRangeAxis().setLabelPaint(textColor);
		pp.getRangeAxis().setTickLabelPaint(textColor);
	}
	if (ytickunit > 0) {
		((NumberAxis) pp.getRangeAxis()).setTickUnit(new NumberTickUnit(ytickunit));
	}

	if (ylabel != null && !ylabel.isEmpty()) {
		pp.getRangeAxis().setLabel(ylabel);
	}
	if (this.series_label_position.equals("yaxis")) {
		pp.getRangeAxis().setLabel(this.getChartdataset().getDataSeriesIds(scope).iterator().next());
		chart.getLegend().setVisible(false);
	}

	if (xlabel != null && !xlabel.isEmpty()) {
		pp.getDomainAxis().setLabel(xlabel);
	}
	if (textColor != null) {
		pp.getDomainAxis().setLabelPaint(textColor);
		pp.getDomainAxis().setTickLabelPaint(textColor);
		if (this.series_label_position.equals("xaxis")) {
			((SubCategoryAxis)pp.getDomainAxis()).setSubLabelPaint(textColor);
		}			
	}
}