Java Code Examples for org.jfree.chart.renderer.category.LineAndShapeRenderer#setSeriesPaint()

The following examples show how to use org.jfree.chart.renderer.category.LineAndShapeRenderer#setSeriesPaint() . 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 6 votes vote down vote up
@Override
	protected JFreeChart createLineChart() throws JRException
	{
		JFreeChart jfreeChart = super.createLineChart();
		CategoryPlot categoryPlot = (CategoryPlot)jfreeChart.getPlot();
		LineAndShapeRenderer lineRenderer = (LineAndShapeRenderer)categoryPlot.getRenderer();
		lineRenderer.setBaseStroke(new BasicStroke(2f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
//		Stroke stroke = new BasicStroke(2f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);

		for (int i = 0; i < lineRenderer.getRowCount(); i++)
		{
			lineRenderer.setSeriesOutlinePaint(i, ChartThemesConstants.TRANSPARENT_PAINT);
			lineRenderer.setSeriesFillPaint(i, ChartThemesConstants.EYE_CANDY_SIXTIES_GRADIENT_PAINTS.get(i));
			lineRenderer.setSeriesPaint(i, ChartThemesConstants.EYE_CANDY_SIXTIES_GRADIENT_PAINTS.get(i));
			lineRenderer.setSeriesShapesVisible(i,true);
			//it isn't applied at the moment
			//lineRenderer.setSeriesStroke(i,stroke);
			
			//line3DRenderer.setSeriesLinesVisible(i,lineRenderer.getSeriesVisible(i));
		}
//		configureChart(jfreeChart, getPlot());
		return jfreeChart;
	}
 
Example 2
Source File: DefaultChartService.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Returns a line and shape renderer.
 */
private LineAndShapeRenderer getLineRenderer()
{
    LineAndShapeRenderer renderer = new LineAndShapeRenderer();

    for ( int i = 0; i < COLORS.length; i++ )
    {
        renderer.setSeriesPaint( i, COLORS[i] );
    }

    return renderer;
}
 
Example 3
Source File: ChartImageGenerator.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Returns a line and shape renderer.
 */
private LineAndShapeRenderer getLineRenderer()
{
    LineAndShapeRenderer renderer = new LineAndShapeRenderer();

    for ( int i = 0; i < COLORS.length; i++ )
    {
        renderer.setSeriesPaint( i, COLORS[i] );
    }

    return renderer;
}
 
Example 4
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 5
Source File: ParetoChartPlotter.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
private JFreeChart createChart() {
	if (data.getItemCount() > 0) {
		// get cumulative percentages
		KeyedValues cumulative = DataUtilities.getCumulativePercentages(data);

		CategoryDataset categoryDataset = DatasetUtilities.createCategoryDataset(
				"Count for " + this.dataTable.getColumnName(this.countColumn) + " = " + countValue, data);

		// create the chart...
		final JFreeChart chart = ChartFactory.createBarChart(null, // chart title
				this.dataTable.getColumnName(this.groupByColumn), // domain axis label
				"Count", // range axis label
				categoryDataset, // data
				PlotOrientation.VERTICAL, true, // include legend
				true, false);

		// set the background color for the chart...
		chart.setBackgroundPaint(Color.WHITE);

		// get a reference to the plot for further customization...
		CategoryPlot plot = chart.getCategoryPlot();

		CategoryAxis domainAxis = plot.getDomainAxis();
		domainAxis.setLowerMargin(0.02);
		domainAxis.setUpperMargin(0.02);
		domainAxis.setLabelFont(LABEL_FONT_BOLD);
		domainAxis.setTickLabelFont(LABEL_FONT);

		// set the range axis to display integers only...
		NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
		rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits(Locale.US));
		rangeAxis.setLabelFont(LABEL_FONT_BOLD);
		rangeAxis.setTickLabelFont(LABEL_FONT);

		// second data set (cumulative percentages)
		CategoryDataset dataset2 = DatasetUtilities.createCategoryDataset("Cumulative (Percent)", cumulative);

		LineAndShapeRenderer renderer2 = new LineAndShapeRenderer();
		renderer2.setSeriesPaint(0, SwingTools.VERY_DARK_BLUE.darker());

		NumberAxis axis2 = new NumberAxis("Percent of " + countValue);
		axis2.setNumberFormatOverride(NumberFormat.getPercentInstance());
		axis2.setLabelFont(LABEL_FONT_BOLD);
		axis2.setTickLabelFont(LABEL_FONT);

		plot.setRangeAxis(1, axis2);
		plot.setDataset(1, dataset2);
		plot.setRenderer(1, renderer2);
		plot.mapDatasetToRangeAxis(1, 1);

		axis2.setTickUnit(new NumberTickUnit(0.1));

		// show grid lines
		plot.setRangeGridlinesVisible(true);

		// bring cumulative line to front
		plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

		if (isLabelRotating()) {
			domainAxis.setTickLabelsVisible(true);
			domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2.0d));
		}

		return chart;
	} else {
		return null;
	}
}
 
Example 6
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 7
Source File: ChartRendererFactory.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
private static void configureLineAndShapeRenderer(LineAndShapeRenderer renderer, ValueSource valueSource,
		PlotInstance plotInstance) {
	ValueSourceData valueSourceData = plotInstance.getPlotData().getValueSourceData(valueSource);
	int seriesCount = valueSourceData.getSeriesCount();
	SeriesFormat seriesFormat = valueSource.getSeriesFormat();
	DimensionConfig domainConfig = valueSource.getDomainConfig();
	DimensionConfig colorDimensionConfig = plotInstance.getCurrentPlotConfigurationClone().getDimensionConfig(
			PlotDimension.COLOR);
	DimensionConfig shapeDimensionConfig = plotInstance.getCurrentPlotConfigurationClone().getDimensionConfig(
			PlotDimension.SHAPE);

	renderer.setDefaultEntityRadius(4);

	// loop all series and set series format
	for (int seriesIdx = 0; seriesIdx < seriesCount; ++seriesIdx) {
		// configure linestyle
		if (seriesFormat.getLineStyle() != LineStyle.NONE) {
			renderer.setSeriesLinesVisible(seriesIdx, true);
			renderer.setSeriesStroke(seriesIdx, seriesFormat.getStroke(), false);
		} else {
			renderer.setSeriesLinesVisible(seriesIdx, false);
		}

		// configure series shape if necessary
		if (!SeriesFormat.calculateIndividualFormatForEachItem(domainConfig, shapeDimensionConfig)) {
			if (seriesFormat.getItemShape() != ItemShape.NONE) {
				renderer.setSeriesShapesVisible(seriesIdx, true);
				renderer.setSeriesShape(seriesIdx, seriesFormat.getItemShape().getShape());
			} else {
				renderer.setSeriesShapesVisible(seriesIdx, false);
			}
		}

		// configure series color if necessary
		if (!SeriesFormat.calculateIndividualFormatForEachItem(domainConfig, colorDimensionConfig)) {
			Color itemColor = seriesFormat.getItemColor();
			renderer.setSeriesPaint(seriesIdx, itemColor);
		}
		renderer.setSeriesOutlinePaint(seriesIdx, PlotConfiguration.DEFAULT_SERIES_OUTLINE_PAINT);
		renderer.setUseOutlinePaint(true);
	}
}