Java Code Examples for org.jfree.chart.renderer.category.CategoryItemRenderer#setBaseItemLabelsVisible()

The following examples show how to use org.jfree.chart.renderer.category.CategoryItemRenderer#setBaseItemLabelsVisible() . 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: ScheduleReport.java    From ezScrum with GNU General Public License v2.0 6 votes vote down vote up
private void setAttribute(JFreeChart chart) {
	// 圖案與文字的間隔
	LegendTitle legend = chart.getLegend();
	legend.setBorder(1, 1, 1, 1);

	CategoryPlot plot = chart.getCategoryPlot();
	// 設定WorkItem的屬性
	CategoryAxis domainAxis = plot.getDomainAxis();
	domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45); // 字體角度
	domainAxis.setTickLabelFont(new Font("新細明體", Font.TRUETYPE_FONT, 12)); // 字體

	// 設定Date的屬性
	DateAxis da = (DateAxis) plot.getRangeAxis(0);
	setDateAxis(da);

	// 設定實體的顯示名稱
	CategoryItemRenderer render = plot.getRenderer(0);
	DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
	CategoryItemLabelGenerator generator = new IntervalCategoryItemLabelGenerator(
			"{3} ~ {4}", format);
	render.setBaseItemLabelGenerator(generator);
	render.setBaseItemLabelPaint(Color.BLUE);
	render.setBaseItemLabelsVisible(true);
	render.setBaseItemLabelFont(new Font("黑體", Font.TRUETYPE_FONT, 8));
	render.setSeriesPaint(0, Color.RED);
}
 
Example 2
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 3
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;
	}