Java Code Examples for org.jfree.chart.renderer.category.BarRenderer#setBaseItemLabelGenerator()

The following examples show how to use org.jfree.chart.renderer.category.BarRenderer#setBaseItemLabelGenerator() . 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: GenericChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 *
 */
protected JFreeChart createGanttChart() throws JRException
{
	//FIXMECHART legend/tooltip/url should come from plot?
	
	ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
	JFreeChart jfreeChart =
		ChartFactory.createGanttChart(
			evaluateTextExpression(getChart().getTitleExpression()),
			evaluateTextExpression(((JRBarPlot)getPlot()).getCategoryAxisLabelExpression()),
			evaluateTextExpression(((JRBarPlot)getPlot()).getValueAxisLabelExpression()),
			(GanttCategoryDataset)getDataset(),
			isShowLegend(),
			true,  //FIXMECHART tooltip: I guess BarPlot is not the best for gantt
			false
			);

	configureChart(jfreeChart, getPlot());
	
	CategoryPlot categoryPlot = (CategoryPlot)jfreeChart.getPlot();
	//plot.setNoDataMessage("No data to display");
	
	JRBarPlot barPlot = (JRBarPlot)getPlot();
	boolean isShowTickMarks = barPlot.getShowTickMarks() == null ? true : barPlot.getShowTickMarks();
	boolean isShowTickLabels = barPlot.getShowTickLabels() == null ? true : barPlot.getShowTickLabels();
	boolean isShowLabels = barPlot.getShowLabels() == null ? false : barPlot.getShowLabels();
	
	categoryPlot.getDomainAxis().setTickMarksVisible(isShowTickMarks);
	categoryPlot.getDomainAxis().setTickLabelsVisible(isShowTickLabels);
	// Handle the axis formating for the category axis
	configureAxis(
		categoryPlot.getDomainAxis(), barPlot.getCategoryAxisLabelFont(),
		barPlot.getCategoryAxisLabelColor(), barPlot.getCategoryAxisTickLabelFont(),
		barPlot.getCategoryAxisTickLabelColor(), barPlot.getCategoryAxisTickLabelMask(), barPlot.getCategoryAxisVerticalTickLabels(),
		barPlot.getOwnCategoryAxisLineColor(), false, null, null
		);
	((DateAxis)categoryPlot.getRangeAxis()).setTickMarksVisible(isShowTickMarks);
	((DateAxis)categoryPlot.getRangeAxis()).setTickLabelsVisible(isShowTickLabels);
	// Handle the axis formating for the value axis
	configureAxis(
		categoryPlot.getRangeAxis(), barPlot.getValueAxisLabelFont(),
		barPlot.getValueAxisLabelColor(), barPlot.getValueAxisTickLabelFont(),
		barPlot.getValueAxisTickLabelColor(), barPlot.getValueAxisTickLabelMask(), barPlot.getValueAxisVerticalTickLabels(),
		barPlot.getOwnValueAxisLineColor(), true,
		(Comparable<?>)evaluateExpression(barPlot.getRangeAxisMinValueExpression()),
		(Comparable<?>)evaluateExpression(barPlot.getRangeAxisMaxValueExpression()));

	BarRenderer categoryRenderer = (BarRenderer)categoryPlot.getRenderer();
	categoryRenderer.setBaseItemLabelGenerator((CategoryItemLabelGenerator)getLabelGenerator());
	categoryRenderer.setBaseItemLabelsVisible(isShowLabels);
	categoryRenderer.setShadowVisible(false);

	return jfreeChart;
}
 
Example 2
Source File: SimpleChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 *
 */
protected JFreeChart createGanttChart() throws JRException
{
	//FIXMECHART legend/tooltip/url should come from plot?
	
	ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
	JFreeChart jfreeChart =
		ChartFactory.createGanttChart(
			evaluateTextExpression(getChart().getTitleExpression()),
			evaluateTextExpression(((JRBarPlot)getPlot()).getCategoryAxisLabelExpression()),
			evaluateTextExpression(((JRBarPlot)getPlot()).getValueAxisLabelExpression()),
			(GanttCategoryDataset)getDataset(),
			isShowLegend(),
			true,  //FIXMECHART tooltip: I guess BarPlot is not the best for gantt
			false
			);

	configureChart(jfreeChart, getPlot());
	
	CategoryPlot categoryPlot = (CategoryPlot)jfreeChart.getPlot();
	//plot.setNoDataMessage("No data to display");
	
	JRBarPlot barPlot = (JRBarPlot)getPlot();
	boolean isShowTickMarks = barPlot.getShowTickMarks() == null ? true : barPlot.getShowTickMarks();
	boolean isShowTickLabels = barPlot.getShowTickLabels() == null ? true : barPlot.getShowTickLabels();
	boolean isShowLabels = barPlot.getShowLabels() == null ? false : barPlot.getShowLabels();
	
	//FIXMETHEME these are useless if the theme settings apply after regardless of these; check all
	categoryPlot.getDomainAxis().setTickMarksVisible(isShowTickMarks);
	categoryPlot.getDomainAxis().setTickLabelsVisible(isShowTickLabels);
	// Handle the axis formating for the category axis
	configureAxis(
		categoryPlot.getDomainAxis(), barPlot.getCategoryAxisLabelFont(),
		barPlot.getCategoryAxisLabelColor(), barPlot.getCategoryAxisTickLabelFont(),
		barPlot.getCategoryAxisTickLabelColor(), barPlot.getCategoryAxisTickLabelMask(), barPlot.getCategoryAxisVerticalTickLabels(),
		barPlot.getOwnCategoryAxisLineColor(), getDomainAxisSettings(), 
		(Comparable<?>)evaluateExpression(barPlot.getDomainAxisMinValueExpression()), 
		(Comparable<?>)evaluateExpression(barPlot.getDomainAxisMaxValueExpression())
		);

	((DateAxis)categoryPlot.getRangeAxis()).setTickMarksVisible(isShowTickMarks);
	((DateAxis)categoryPlot.getRangeAxis()).setTickLabelsVisible(isShowTickLabels);
	// Handle the axis formating for the value axis
	configureAxis(
		categoryPlot.getRangeAxis(), barPlot.getValueAxisLabelFont(),
		barPlot.getValueAxisLabelColor(), barPlot.getValueAxisTickLabelFont(),
		barPlot.getValueAxisTickLabelColor(), barPlot.getValueAxisTickLabelMask(), barPlot.getValueAxisVerticalTickLabels(),
		barPlot.getOwnValueAxisLineColor(), getRangeAxisSettings(),
		(Comparable<?>)evaluateExpression(barPlot.getRangeAxisMinValueExpression()), 
		(Comparable<?>)evaluateExpression(barPlot.getRangeAxisMaxValueExpression())
		);

	BarRenderer categoryRenderer = (BarRenderer)categoryPlot.getRenderer();
	categoryRenderer.setBaseItemLabelGenerator((CategoryItemLabelGenerator)getLabelGenerator());
	categoryRenderer.setBaseItemLabelsVisible(isShowLabels);
	categoryRenderer.setShadowVisible(false);

	return jfreeChart;
}
 
Example 3
Source File: AbstractCategoryItemRendererTests.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Checks that all fields are distinguished.
 */
public void testEquals() {
    BarRenderer r1 = new BarRenderer();
    BarRenderer r2 = new BarRenderer();
    assertEquals(r1, r2);

    // the plot field is NOT tested

    // toolTipGeneratorList
    r1.setSeriesToolTipGenerator(1, new StandardCategoryToolTipGenerator());
    assertFalse(r1.equals(r2));
    r2.setSeriesToolTipGenerator(1, new StandardCategoryToolTipGenerator());
    assertTrue(r1.equals(r2));

    // baseToolTipGenerator
    r1.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator("{2}",
            NumberFormat.getInstance()));
    assertFalse(r1.equals(r2));
    r2.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator("{2}",
            NumberFormat.getInstance()));
    assertTrue(r1.equals(r2));

    // itemLabelGeneratorList
    r1.setSeriesItemLabelGenerator(1,
            new StandardCategoryItemLabelGenerator());
    assertFalse(r1.equals(r2));
    r2.setSeriesItemLabelGenerator(1,
            new StandardCategoryItemLabelGenerator());
    assertTrue(r1.equals(r2));

    // baseItemLabelGenerator
    r1.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator(
            "{2}", NumberFormat.getInstance()));
    assertFalse(r1.equals(r2));
    r2.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator(
            "{2}", NumberFormat.getInstance()));
    assertTrue(r1.equals(r2));

    // urlGeneratorList
    r1.setSeriesURLGenerator(1, new StandardCategoryURLGenerator());
    assertFalse(r1.equals(r2));
    r2.setSeriesURLGenerator(1, new StandardCategoryURLGenerator());
    assertTrue(r1.equals(r2));

    // baseItemURLGenerator
    r1.setBaseURLGenerator(new StandardCategoryURLGenerator(
            "abc.html"));
    assertFalse(r1.equals(r2));
    r2.setBaseURLGenerator(new StandardCategoryURLGenerator(
            "abc.html"));
    assertTrue(r1.equals(r2));

    // legendItemLabelGenerator
    r1.setLegendItemLabelGenerator(new StandardCategorySeriesLabelGenerator(
            "XYZ"));
    assertFalse(r1.equals(r2));
    r2.setLegendItemLabelGenerator(new StandardCategorySeriesLabelGenerator(
            "XYZ"));
    assertTrue(r1.equals(r2));

    // legendItemToolTipGenerator
    r1.setLegendItemToolTipGenerator(
            new StandardCategorySeriesLabelGenerator("ToolTip"));
    assertFalse(r1.equals(r2));
    r2.setLegendItemToolTipGenerator(
            new StandardCategorySeriesLabelGenerator("ToolTip"));
    assertTrue(r1.equals(r2));

    // legendItemURLGenerator
    r1.setLegendItemURLGenerator(
            new StandardCategorySeriesLabelGenerator("URL"));
    assertFalse(r1.equals(r2));
    r2.setLegendItemURLGenerator(
            new StandardCategorySeriesLabelGenerator("URL"));
    assertTrue(r1.equals(r2));

    // background annotation
    r1.addAnnotation(new CategoryTextAnnotation("ABC", "A", 2.0),
            Layer.BACKGROUND);
    assertFalse(r1.equals(r2));
    r2.addAnnotation(new CategoryTextAnnotation("ABC", "A", 2.0),
            Layer.BACKGROUND);
    assertTrue(r1.equals(r2));

    // foreground annotation
    r1.addAnnotation(new CategoryTextAnnotation("DEF", "B", 4.0),
            Layer.FOREGROUND);
    assertFalse(r1.equals(r2));
    r2.addAnnotation(new CategoryTextAnnotation("DEF", "B", 4.0),
            Layer.FOREGROUND);
    assertTrue(r1.equals(r2));
}
 
Example 4
Source File: AbstractCategoryItemRendererTests.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Checks that all fields are distinguished.
 */
public void testEquals() {
    BarRenderer r1 = new BarRenderer();
    BarRenderer r2 = new BarRenderer();
    assertEquals(r1, r2);
    
    // the plot field is NOT tested
    
    // toolTipGeneratorList
    r1.setSeriesToolTipGenerator(1, new StandardCategoryToolTipGenerator());
    assertFalse(r1.equals(r2));
    r2.setSeriesToolTipGenerator(1, new StandardCategoryToolTipGenerator());
    assertTrue(r1.equals(r2));
    
    // baseToolTipGenerator
    r1.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator("{2}", 
            NumberFormat.getInstance()));
    assertFalse(r1.equals(r2));
    r2.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator("{2}", 
            NumberFormat.getInstance()));
    assertTrue(r1.equals(r2));
    
    // itemLabelGeneratorList
    r1.setSeriesItemLabelGenerator(1, 
            new StandardCategoryItemLabelGenerator());
    assertFalse(r1.equals(r2));
    r2.setSeriesItemLabelGenerator(1, 
            new StandardCategoryItemLabelGenerator());
    assertTrue(r1.equals(r2));
    
    // baseItemLabelGenerator
    r1.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator(
            "{2}", NumberFormat.getInstance()));
    assertFalse(r1.equals(r2));
    r2.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator(
            "{2}", NumberFormat.getInstance()));
    assertTrue(r1.equals(r2));
    
    // urlGeneratorList
    r1.setSeriesURLGenerator(1, new StandardCategoryURLGenerator());
    assertFalse(r1.equals(r2));
    r2.setSeriesURLGenerator(1, new StandardCategoryURLGenerator());
    assertTrue(r1.equals(r2));
    
    // baseItemURLGenerator
    r1.setBaseURLGenerator(new StandardCategoryURLGenerator(
            "abc.html"));
    assertFalse(r1.equals(r2));
    r2.setBaseURLGenerator(new StandardCategoryURLGenerator(
            "abc.html"));
    assertTrue(r1.equals(r2));
    
    // legendItemLabelGenerator
    r1.setLegendItemLabelGenerator(new StandardCategorySeriesLabelGenerator(
            "XYZ"));
    assertFalse(r1.equals(r2));
    r2.setLegendItemLabelGenerator(new StandardCategorySeriesLabelGenerator(
            "XYZ"));
    assertTrue(r1.equals(r2));
    
    // legendItemToolTipGenerator
    r1.setLegendItemToolTipGenerator(
            new StandardCategorySeriesLabelGenerator("ToolTip"));
    assertFalse(r1.equals(r2));
    r2.setLegendItemToolTipGenerator(
            new StandardCategorySeriesLabelGenerator("ToolTip"));
    assertTrue(r1.equals(r2));

    // legendItemURLGenerator
    r1.setLegendItemURLGenerator(
            new StandardCategorySeriesLabelGenerator("URL"));
    assertFalse(r1.equals(r2));
    r2.setLegendItemURLGenerator(
            new StandardCategorySeriesLabelGenerator("URL"));
    assertTrue(r1.equals(r2));
    
    // background annotation
    r1.addAnnotation(new CategoryTextAnnotation("ABC", "A", 2.0), 
            Layer.BACKGROUND);
    assertFalse(r1.equals(r2));
    r2.addAnnotation(new CategoryTextAnnotation("ABC", "A", 2.0), 
            Layer.BACKGROUND);
    assertTrue(r1.equals(r2));
    
    // foreground annotation
    r1.addAnnotation(new CategoryTextAnnotation("DEF", "B", 4.0),
            Layer.FOREGROUND);
    assertFalse(r1.equals(r2));
    r2.addAnnotation(new CategoryTextAnnotation("DEF", "B", 4.0), 
            Layer.FOREGROUND);
    assertTrue(r1.equals(r2));
}