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

The following examples show how to use org.jfree.chart.renderer.category.BarRenderer#setSeriesItemLabelsVisible() . 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: EyeCandySixtiesChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
protected JFreeChart createGanttChart() throws JRException
{

	JFreeChart jfreeChart = super.createGanttChart();
	CategoryPlot categoryPlot = (CategoryPlot)jfreeChart.getPlot();
	categoryPlot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.STANDARD);
	categoryPlot.setDomainGridlinesVisible(true);
	categoryPlot.setDomainGridlinePosition(CategoryAnchor.END);
	categoryPlot.setDomainGridlineStroke(new BasicStroke(
			0.5f,
			BasicStroke.CAP_BUTT,
			BasicStroke.JOIN_MITER,
			50,
			new float[] {1},
			0
			)
	);

	categoryPlot.setDomainGridlinePaint(ChartThemesConstants.GRAY_PAINT_134);

	categoryPlot.setRangeGridlinesVisible(true);
	categoryPlot.setRangeGridlineStroke(new BasicStroke(
			0.5f,
			BasicStroke.CAP_BUTT,
			BasicStroke.JOIN_MITER,
			50,
			new float[] {1},
			0
			)
	);

	categoryPlot.setRangeGridlinePaint(ChartThemesConstants.GRAY_PAINT_134);
	categoryPlot.getDomainAxis().setTickLabelsVisible(
			//barPlot.isShowTickLabels()
			true
			);
	CategoryItemRenderer categoryRenderer = categoryPlot.getRenderer();
	categoryRenderer.setBaseItemLabelsVisible(true);
	BarRenderer barRenderer = (BarRenderer)categoryRenderer;
	barRenderer.setSeriesPaint(0, ChartThemesConstants.EYE_CANDY_SIXTIES_COLORS.get(3));
	barRenderer.setSeriesPaint(1, ChartThemesConstants.EYE_CANDY_SIXTIES_COLORS.get(0));
	CategoryDataset categoryDataset = categoryPlot.getDataset();
	if (categoryDataset != null)
	{
		for (int i = 0; i < categoryDataset.getRowCount(); i++)
		{
			barRenderer.setSeriesItemLabelFont(i, categoryPlot.getDomainAxis().getTickLabelFont());
			barRenderer.setSeriesItemLabelsVisible(i, true);
		}
	}
	categoryPlot.setOutlinePaint(Color.DARK_GRAY);
	categoryPlot.setOutlineStroke(new BasicStroke(1.5f));
	categoryPlot.setOutlineVisible(true);
	return jfreeChart;
}
 
Example 2
Source File: AegeanChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
	protected JFreeChart createGanttChart() throws JRException
	{

		JFreeChart jfreeChart = super.createGanttChart();
		CategoryPlot categoryPlot = (CategoryPlot)jfreeChart.getPlot();
		categoryPlot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.STANDARD);
		categoryPlot.setDomainGridlinesVisible(true);
		categoryPlot.setDomainGridlinePosition(CategoryAnchor.END);
		categoryPlot.setDomainGridlineStroke(new BasicStroke(
				0.5f,
				BasicStroke.CAP_BUTT,
				BasicStroke.JOIN_MITER,
				50,
				new float[] {1},
				0
				)
		);

		categoryPlot.setDomainGridlinePaint(ChartThemesConstants.GRAY_PAINT_217);

		categoryPlot.setRangeGridlinesVisible(true);
		categoryPlot.setRangeGridlineStroke(new BasicStroke(
				0.5f,
				BasicStroke.CAP_BUTT,
				BasicStroke.JOIN_MITER,
				50,
				new float[] {1},
				0
				)
		);

		categoryPlot.setRangeGridlinePaint(ChartThemesConstants.GRAY_PAINT_217);
//		JRBarPlot barPlot = (BarPlot)categoryPlot;
//		categoryPlot.getDomainAxis().setTickLabelsVisible(
//				categoryPlot.getShowTickLabels() == null ? true : barPlot.getShowTickLabels().
//				true
//				);
		CategoryItemRenderer categoryRenderer = categoryPlot.getRenderer();
		categoryRenderer.setBaseItemLabelsVisible(true);
		BarRenderer barRenderer = (BarRenderer)categoryRenderer;
		@SuppressWarnings("unchecked")
		List<Paint> seriesPaints = (List<Paint>)getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.SERIES_COLORS);
		barRenderer.setSeriesPaint(0, seriesPaints.get(3));
		barRenderer.setSeriesPaint(1, seriesPaints.get(0));
		CategoryDataset categoryDataset = categoryPlot.getDataset();
		if(categoryDataset != null)
		{
			for(int i = 0; i < categoryDataset.getRowCount(); i++)
			{
				barRenderer.setSeriesItemLabelFont(i, categoryPlot.getDomainAxis().getTickLabelFont());
				barRenderer.setSeriesItemLabelsVisible(i, true);
	//			barRenderer.setSeriesPaint(i, GRADIENT_PAINTS[i]);
	//			CategoryMarker categoryMarker = new CategoryMarker(categoryDataset.getColumnKey(i),MARKER_COLOR, new BasicStroke(1f));
	//			categoryMarker.setAlpha(0.5f);
	//			categoryPlot.addDomainMarker(categoryMarker, Layer.BACKGROUND);
			}
		}
		categoryPlot.setOutlinePaint(Color.DARK_GRAY);
		categoryPlot.setOutlineStroke(new BasicStroke(1.5f));
		categoryPlot.setOutlineVisible(true);
		return jfreeChart;
	}
 
Example 3
Source File: ParetoChartPlotter.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
public void paintParetoChart(Graphics graphics) {
	prepareData();

	JFreeChart chart = createChart();

	if (chart != null) {
		// set the background color for the chart...
		chart.setBackgroundPaint(Color.white);
		chart.getPlot().setBackgroundPaint(Color.WHITE);

		// bar renderer --> own 3D effect
		CategoryPlot plot = chart.getCategoryPlot();
		BarRenderer renderer = (BarRenderer) plot.getRenderer();
		// renderer.setBarPainter(new StandardBarPainter());
		renderer.setBarPainter(new RapidBarPainter());

		renderer.setSeriesPaint(0, getColorProvider(true).getPointColor(1));

		// labels on top of bars
		Map<String, String> barItemLabels = new HashMap<>();
		Map<String, String> cumulativeItemLabels = new HashMap<>();
		int groupSum = 0;
		int totalSum = 0;
		for (Object key : totalData.getKeys()) {
			String k = (String) key;
			try {
				Number groupValue = data.getValue(k);
				Number totalValue = totalData.getValue(k);
				groupSum += groupValue.intValue();
				totalSum += totalValue.intValue();
				barItemLabels.put(
						k,
						Tools.formatIntegerIfPossible(groupValue.doubleValue()) + " / "
								+ Tools.formatIntegerIfPossible(totalValue.doubleValue()));
				cumulativeItemLabels.put(k, groupSum + " / " + totalSum);
			} catch (UnknownKeyException e) {
				// do nothing
			}
		}
		renderer.setSeriesItemLabelFont(0, LABEL_FONT);

		if (showBarLabelsFlag) {
			renderer.setSeriesItemLabelsVisible(0, true);
			renderer.setSeriesItemLabelGenerator(0, new ParetoChartItemLabelGenerator(barItemLabels));

			if (isLabelRotating()) {
				renderer.setSeriesPositiveItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,
						TextAnchor.CENTER_LEFT, TextAnchor.CENTER_LEFT, -Math.PI / 2.0d));
				renderer.setSeriesNegativeItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,
						TextAnchor.CENTER_LEFT, TextAnchor.CENTER_LEFT, -Math.PI / 2.0d));
			}
		}

		LineAndShapeRenderer renderer2 = (LineAndShapeRenderer) chart.getCategoryPlot().getRenderer(1);
		renderer2.setSeriesPaint(0, Color.GRAY.darker().darker());
		renderer2.setSeriesItemLabelFont(0, LABEL_FONT);
		renderer2.setSeriesItemLabelPaint(0, Color.BLACK);
		if (isLabelRotating()) {
			renderer2.setSeriesPositiveItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6,
					TextAnchor.CENTER_RIGHT, TextAnchor.CENTER_RIGHT, -Math.PI / 2.0d));
			renderer2.setSeriesNegativeItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6,
					TextAnchor.CENTER_RIGHT, TextAnchor.CENTER_RIGHT, -Math.PI / 2.0d));
		} else {
			renderer2.setSeriesPositiveItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.OUTSIDE10,
					TextAnchor.BOTTOM_RIGHT));
			renderer2.setSeriesNegativeItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.OUTSIDE10,
					TextAnchor.BOTTOM_RIGHT));
		}

		if (showCumulativeLabelsFlag) {
			renderer2.setSeriesItemLabelsVisible(0, true);
			renderer2.setSeriesItemLabelGenerator(0, new ParetoChartItemLabelGenerator(cumulativeItemLabels));
		}

		// draw outlines
		renderer.setDrawBarOutline(true);

		// gridline colors
		plot.setRangeGridlinePaint(Color.BLACK);

		// legend settings
		LegendTitle legend = chart.getLegend();
		if (legend != null) {
			legend.setPosition(RectangleEdge.TOP);
			legend.setFrame(BlockBorder.NONE);
			legend.setHorizontalAlignment(HorizontalAlignment.LEFT);
			legend.setItemFont(LABEL_FONT);
		}

		Rectangle2D drawRect = new Rectangle2D.Double(0, 0, getWidth(), getHeight());
		chart.draw((Graphics2D) graphics, drawRect);
	}
}
 
Example 4
Source File: AbstractRendererTests.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Some checks for the hashCode() method.
 */
public void testHashCode() {
    BarRenderer r1 = new BarRenderer();
    BarRenderer r2 = new BarRenderer();
    assertTrue(r1.hashCode() == r2.hashCode());

    r1.setSeriesVisible(1, Boolean.FALSE);
    assertFalse(r1.hashCode() == r2.hashCode());
    r2.setSeriesVisible(1, Boolean.FALSE);
    assertTrue(r1.hashCode() == r2.hashCode());

    r1.setBaseSeriesVisible(false);
    assertFalse(r1.hashCode() == r2.hashCode());
    r2.setBaseSeriesVisible(false);
    assertTrue(r1.hashCode() == r2.hashCode());

    r1.setSeriesVisibleInLegend(1, Boolean.FALSE);
    assertFalse(r1.hashCode() == r2.hashCode());
    r2.setSeriesVisibleInLegend(1, Boolean.FALSE);
    assertTrue(r1.hashCode() == r2.hashCode());

    r1.setBaseSeriesVisibleInLegend(false);
    assertFalse(r1.hashCode() == r2.hashCode());
    r2.setBaseSeriesVisibleInLegend(false);
    assertTrue(r1.hashCode() == r2.hashCode());

    r1.setSeriesPaint(0, new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f,
            4.0f, Color.BLUE));
    assertFalse(r1.hashCode() == r2.hashCode());
    r2.setSeriesPaint(0, new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f,
            4.0f, Color.BLUE));
    assertTrue(r1.hashCode() == r2.hashCode());

    r1.setBasePaint(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f,
            4.0f, Color.BLUE));
    assertFalse(r1.hashCode() == r2.hashCode());
    r2.setBasePaint(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f,
            4.0f, Color.BLUE));
    assertTrue(r1.hashCode() == r2.hashCode());

    r1.setSeriesFillPaint(0, new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f,
            4.0f, Color.BLUE));
    assertFalse(r1.hashCode() == r2.hashCode());
    r2.setSeriesFillPaint(0, new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f,
            4.0f, Color.BLUE));
    assertTrue(r1.hashCode() == r2.hashCode());

    r1.setBaseFillPaint(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f,
            4.0f, Color.BLUE));
    assertFalse(r1.hashCode() == r2.hashCode());
    r2.setBaseFillPaint(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f,
            4.0f, Color.BLUE));
    assertTrue(r1.hashCode() == r2.hashCode());

    r1.setSeriesOutlinePaint(0, new GradientPaint(1.0f, 2.0f, Color.RED,
            3.0f, 4.0f, Color.BLUE));
    assertFalse(r1.hashCode() == r2.hashCode());
    r2.setSeriesOutlinePaint(0, new GradientPaint(1.0f, 2.0f, Color.RED,
            3.0f, 4.0f, Color.BLUE));
    assertTrue(r1.hashCode() == r2.hashCode());

    r1.setBaseOutlinePaint(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f,
            4.0f, Color.BLUE));
    assertFalse(r1.hashCode() == r2.hashCode());
    r2.setBaseOutlinePaint(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f,
            4.0f, Color.BLUE));
    assertTrue(r1.hashCode() == r2.hashCode());

    r1.setSeriesStroke(0, new BasicStroke(1.1f));
    assertFalse(r1.hashCode() == r2.hashCode());
    r2.setSeriesStroke(0, new BasicStroke(1.1f));
    assertTrue(r1.hashCode() == r2.hashCode());

    r1.setBaseStroke(new BasicStroke(1.5f));
    assertFalse(r1.hashCode() == r2.hashCode());
    r2.setBaseStroke(new BasicStroke(1.5f));
    assertTrue(r1.hashCode() == r2.hashCode());

    r1.setSeriesOutlineStroke(1, new BasicStroke(1.5f));
    assertFalse(r1.hashCode() == r2.hashCode());
    r2.setSeriesOutlineStroke(1, new BasicStroke(1.5f));
    assertTrue(r1.hashCode() == r2.hashCode());

    r1.setBaseOutlineStroke(new BasicStroke(2.0f));
    assertFalse(r1.hashCode() == r2.hashCode());
    r2.setBaseOutlineStroke(new BasicStroke(2.0f));
    assertTrue(r1.hashCode() == r2.hashCode());

    r1.setSeriesItemLabelsVisible(1, true);
    assertFalse(r1.hashCode() == r2.hashCode());
    r2.setSeriesItemLabelsVisible(1, true);
    assertTrue(r1.hashCode() == r2.hashCode());

    r1.setBaseItemLabelsVisible(true);
    assertFalse(r1.hashCode() == r2.hashCode());
    r2.setBaseItemLabelsVisible(true);
    assertTrue(r1.hashCode() == r2.hashCode());
}