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

The following examples show how to use org.jfree.chart.renderer.category.BarRenderer#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 createBarChart() throws JRException
{
	JFreeChart jfreeChart = super.createBarChart();

	CategoryPlot categoryPlot = (CategoryPlot)jfreeChart.getPlot();
	//categoryPlot.setOrientation(PlotOrientation.HORIZONTAL);
	BarRenderer barRenderer = (BarRenderer)categoryPlot.getRenderer();
	barRenderer.setItemMargin(0);
	barRenderer.setGradientPaintTransformer(
		new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL)
		);
	CategoryDataset categoryDataset = categoryPlot.getDataset();
	if (categoryDataset != null)
	{
		for (int i = 0; i < categoryDataset.getRowCount(); i++)
		{
			barRenderer.setSeriesPaint(i, ChartThemesConstants.EYE_CANDY_SIXTIES_GRADIENT_PAINTS.get(i));
		}
	}
	return jfreeChart;
}
 
Example 2
Source File: EyeCandySixtiesChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected JFreeChart createStackedBarChart() throws JRException
{
	JFreeChart jfreeChart = super.createStackedBarChart();

	CategoryPlot categoryPlot = (CategoryPlot)jfreeChart.getPlot();
	//categoryPlot.setOrientation(PlotOrientation.HORIZONTAL);
	BarRenderer barRenderer = (BarRenderer)categoryPlot.getRenderer();
	barRenderer.setItemMargin(0);
	barRenderer.setGradientPaintTransformer(
		new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL)
		);

	CategoryDataset categoryDataset = categoryPlot.getDataset();
	if (categoryDataset != null)
	{
		for (int i = 0; i < categoryDataset.getRowCount(); i++)
		{
			barRenderer.setSeriesPaint(i, ChartThemesConstants.EYE_CANDY_SIXTIES_GRADIENT_PAINTS.get(i));
		}
	}
	return jfreeChart;
}
 
Example 3
Source File: BeltNominalColumnStatisticsModel.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Creates the histogram chart.
 */
private JFreeChart createBarChart() {
	JFreeChart chart = ChartFactory.createBarChart(null, null, null, createBarDataset(), PlotOrientation.VERTICAL,
			false, false, false);
	setDefaultChartFonts(chart);
	chart.setBackgroundPaint(null);
	chart.setBackgroundImageAlpha(0.0f);

	CategoryPlot plot = (CategoryPlot) chart.getPlot();
	plot.setRangeGridlinesVisible(false);
	plot.setDomainGridlinesVisible(false);
	plot.setOutlineVisible(false);
	plot.setRangeZeroBaselineVisible(false);
	plot.setDomainGridlinesVisible(false);
	plot.setBackgroundPaint(COLOR_INVISIBLE);
	plot.setBackgroundImageAlpha(0.0f);

	BarRenderer renderer = (BarRenderer) plot.getRenderer();
	renderer.setSeriesPaint(0, AttributeGuiTools.getColorForValueType(Ontology.NOMINAL));
	renderer.setBarPainter(new StandardBarPainter());
	renderer.setDrawBarOutline(true);
	renderer.setShadowVisible(false);

	return chart;
}
 
Example 4
Source File: NominalAttributeStatisticsModel.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Creates the histogram chart.
 * 
 * @return
 */
private JFreeChart createBarChart() {
	JFreeChart chart = ChartFactory.createBarChart(null, null, null, createBarDataset(), PlotOrientation.VERTICAL,
			false, false, false);
	AbstractAttributeStatisticsModel.setDefaultChartFonts(chart);
	chart.setBackgroundPaint(null);
	chart.setBackgroundImageAlpha(0.0f);

	CategoryPlot plot = (CategoryPlot) chart.getPlot();
	plot.setRangeGridlinesVisible(false);
	plot.setDomainGridlinesVisible(false);
	plot.setOutlineVisible(false);
	plot.setRangeZeroBaselineVisible(false);
	plot.setDomainGridlinesVisible(false);
	plot.setBackgroundPaint(COLOR_INVISIBLE);
	plot.setBackgroundImageAlpha(0.0f);

	BarRenderer renderer = (BarRenderer) plot.getRenderer();
	renderer.setSeriesPaint(0, AttributeGuiTools.getColorForValueType(Ontology.NOMINAL));
	renderer.setBarPainter(new StandardBarPainter());
	renderer.setDrawBarOutline(true);
	renderer.setShadowVisible(false);

	return chart;
}
 
Example 5
Source File: ChartRendererFactory.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
private static void configureBarRenderer(BarRenderer renderer, ValueSource valueSource, PlotInstance plotInstance) {
	StandardBarPainter barPainter = new StandardBarPainter();
	renderer.setBarPainter(barPainter);
	renderer.setGradientPaintTransformer(null);

	ValueSourceData valueSourceData = plotInstance.getPlotData().getValueSourceData(valueSource);
	int seriesCount = valueSourceData.getSeriesCount();
	DimensionConfig domainConfig = valueSource.getDomainConfig();
	DimensionConfig colorDimensionConfig = plotInstance.getCurrentPlotConfigurationClone().getDimensionConfig(
			PlotDimension.COLOR);
	SeriesFormat seriesFormat = valueSource.getSeriesFormat();

	// Loop all series and set series format.
	// Format based on dimension configs will be set later on in initFormatDelegate().
	for (int seriesIdx = 0; seriesIdx < seriesCount; ++seriesIdx) {
		// configure series paint if necessary
		if (!SeriesFormat.calculateIndividualFormatForEachItem(domainConfig, colorDimensionConfig)) {
			renderer.setSeriesPaint(seriesIdx, seriesFormat.getAreaFillPaint());
		}

		// configure general style of the bars
		renderer.setShadowVisible(false);
		renderer.setSeriesOutlinePaint(seriesIdx, PlotConfiguration.DEFAULT_SERIES_OUTLINE_PAINT);
	}
	renderer.setDrawBarOutline(true);
}
 
Example 6
Source File: BarChartCustomizer.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void customize(JFreeChart chart, JRChart jasperChart)
{
	BarRenderer renderer = (BarRenderer) chart.getCategoryPlot().getRenderer();
	renderer.setSeriesPaint(0, Color.green);
	renderer.setSeriesPaint(1, Color.orange);
}
 
Example 7
Source File: DefaultChartService.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Returns a bar renderer.
 */
private BarRenderer getBarRenderer()
{
    BarRenderer renderer = new BarRenderer();

    renderer.setMaximumBarWidth( 0.07 );

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

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

    renderer.setMaximumBarWidth( 0.07 );

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

    return renderer;
}
 
Example 9
Source File: BarChartDemo1.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a sample chart.
 *
 * @param dataset  the dataset.
 *
 * @return The chart.
 */
private static JFreeChart createChart(CategoryDataset dataset) {

    JFreeChart chart = ChartFactory.createBarChart("Bar Chart Demo 1",
            "Category", "Value", dataset, true);                   
    CategoryPlot plot = (CategoryPlot) chart.getPlot();

    // ******************************************************************
    //  More than 150 demo applications are included with the JFreeChart
    //  Developer Guide...for more information, see:
    //
    //  >   http://www.object-refinery.com/jfreechart/guide.html
    //
    // ******************************************************************

    // set the range axis to display integers only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // disable bar outlines...
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    // set up gradient paints for series...
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue,
            0.0f, 0.0f, new Color(0, 0, 64));
    GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green,
            0.0f, 0.0f, new Color(0, 64, 0));
    GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red,
            0.0f, 0.0f, new Color(64, 0, 0));
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(
            CategoryLabelPositions.createUpRotationLabelPositions(
                    Math.PI / 6.0));

    return chart;

}
 
Example 10
Source File: UserChartController.java    From airsonic-advanced with GNU General Public License v3.0 4 votes vote down vote up
private JFreeChart createChart(CategoryDataset dataset, HttpServletRequest request) {
    JFreeChart chart = ChartFactory.createBarChart(null, null, null, dataset, PlotOrientation.HORIZONTAL, false, false, false);

    CategoryPlot plot = chart.getCategoryPlot();
    Paint background = new GradientPaint(0, 0, Color.lightGray, 0, IMAGE_MIN_HEIGHT, Color.white);
    plot.setBackgroundPaint(background);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    LogarithmicAxis rangeAxis = new LogarithmicAxis(null);
    rangeAxis.setStrictValuesFlag(false);
    rangeAxis.setAllowNegativesFlag(true);
    plot.setRangeAxis(rangeAxis);

    // Disable bar outlines.
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    // Set up gradient paint for series.
    GradientPaint gp0 = new GradientPaint(
            0.0f, 0.0f, Color.blue,
            0.0f, 0.0f, new Color(0, 0, 64)
    );
    renderer.setSeriesPaint(0, gp0);

    // Rotate labels.
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));

    // Set theme-specific colors.
    Color bgColor = getBackground(request);
    Color fgColor = getForeground(request);

    chart.setBackgroundPaint(bgColor);

    domainAxis.setTickLabelPaint(fgColor);
    domainAxis.setTickMarkPaint(fgColor);
    domainAxis.setAxisLinePaint(fgColor);

    rangeAxis.setTickLabelPaint(fgColor);
    rangeAxis.setTickMarkPaint(fgColor);
    rangeAxis.setAxisLinePaint(fgColor);

    return chart;
}
 
Example 11
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());
}
 
Example 12
Source File: ServerWideReportManagerImpl.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
private byte[] createToolAnalysisChart (int width, int height)
{
	CategoryDataset dataset = getToolAnalysisDataSet ();
	
	if (dataset == null) {
		return generateNoDataChart(width, height);
	}
			
	JFreeChart chart = ChartFactory.createBarChart (
			null, // chart title
			null, // domain axis label
			null, // range axis label
			dataset, // data
			PlotOrientation.HORIZONTAL, // the plot orientation
			false, // legend
			false, // tooltips
			false // urls
	);
	
	// set background
	chart.setBackgroundPaint (parseColor (statsManager.getChartBackgroundColor ()));

	// set chart border
	chart.setPadding (new RectangleInsets (10, 5, 5, 5));
	chart.setBorderVisible (true);
	chart.setBorderPaint (parseColor ("#cccccc"));

	// set anti alias
	chart.setAntiAlias (true);

	CategoryPlot plot = (CategoryPlot) chart.getPlot ();

	// set transparency
	plot.setForegroundAlpha (0.7f);
	plot.setAxisOffset (new RectangleInsets (5.0, 5.0, 5.0, 5.0));
	plot.setBackgroundPaint (Color.lightGray);
	plot.setDomainGridlinesVisible (false);
	plot.setRangeGridlinesVisible (true);
	plot.setRangeGridlinePaint (Color.white);
	
       CategoryAxis domainAxis = plot.getDomainAxis();
       domainAxis.setVisible(false);
       domainAxis.setUpperMargin (0);
       domainAxis.setLowerMargin (0);
       
       NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
       rangeAxis.setUpperMargin(0.20);
	rangeAxis.setStandardTickUnits (NumberAxis.createIntegerTickUnits ());
       
       BarRenderer renderer = (BarRenderer) plot.getRenderer();
       CategoryItemLabelGenerator generator 
           = new StandardCategoryItemLabelGenerator("{1}", 
                   NumberFormat.getInstance(new ResourceLoader().getLocale()));
       renderer.setDefaultItemLabelGenerator(generator);
       renderer.setDefaultItemLabelFont(new Font("SansSerif", Font.PLAIN, 9));
       renderer.setDefaultItemLabelsVisible(true);
       renderer.setItemMargin (0);
       renderer.setSeriesPaint (0, Color.BLUE);
       
       BufferedImage img = chart.createBufferedImage (width, height);
	final ByteArrayOutputStream out = new ByteArrayOutputStream();
	try{
		ImageIO.write(img, "png", out);
	}catch(IOException e){
		log.warn("Error occurred while generating SiteStats chart image data", e);
	}
	return out.toByteArray();
}
 
Example 13
Source File: MonitoringPage.java    From webanno with Apache License 2.0 4 votes vote down vote up
private JFreeChart createProgressChart(Map<String, Integer> chartValues, int aMaxValue,
        boolean aIsPercentage)
{
    // fill dataset
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    if (aMaxValue > 0) {
        for (String chartValue : chartValues.keySet()) {
            dataset.setValue(chartValues.get(chartValue), "Completion", chartValue);
        }
    }
    
    // create chart
    JFreeChart chart = ChartFactory.createBarChart(null, null, null, dataset,
            PlotOrientation.HORIZONTAL, false, false, false);

    CategoryPlot plot = chart.getCategoryPlot();
    plot.setOutlineVisible(false);
    plot.setBackgroundPaint(null);
    plot.setNoDataMessage("No data");
    plot.setInsets(new RectangleInsets(0, 20, 0, 20));
    if (aMaxValue > 0) {
        plot.getRangeAxis().setRange(0.0, aMaxValue);
        ((NumberAxis) plot.getRangeAxis()).setNumberFormatOverride(new DecimalFormat("0"));
        // For documents less than 10, avoid repeating the number of documents such
        // as 0 0 1 1 1 - NumberTickUnit automatically determines the range
        if (!aIsPercentage && aMaxValue <= 10) {
            TickUnits standardUnits = new TickUnits();
            NumberAxis tick = new NumberAxis();
            tick.setTickUnit(new NumberTickUnit(1));
            standardUnits.add(tick.getTickUnit());
            plot.getRangeAxis().setStandardTickUnits(standardUnits);
        }
    }
    else {
        plot.getRangeAxis().setVisible(false);
        plot.getDomainAxis().setVisible(false);
    }

    BarRenderer renderer = new BarRenderer();
    renderer.setBarPainter(new StandardBarPainter());
    renderer.setShadowVisible(false);
    // renderer.setGradientPaintTransformer(new
    // StandardGradientPaintTransformer(
    // GradientPaintTransformType.HORIZONTAL));
    renderer.setSeriesPaint(0, Color.BLUE);
    chart.getCategoryPlot().setRenderer(renderer);

    return chart;
}
 
Example 14
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 15
Source File: DistributionPlotter.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
private JFreeChart createNominalChart() {
	JFreeChart chart;
	CategoryDataset dataset = createNominalDataSet();

	// create the chart...
	String domainName = dataTable == null ? MODEL_DOMAIN_AXIS_NAME : dataTable.getColumnName(plotColumn);
	chart = ChartFactory.createBarChart(null, // chart title
			domainName, // x axis label
			RANGE_AXIS_NAME, // y axis label
			dataset, // data
			PlotOrientation.VERTICAL, true, // include legend
			true, // tooltips
			false // urls
			);

	CategoryPlot plot = chart.getCategoryPlot();

	BarRenderer renderer = new BarRenderer();
	if (dataset.getRowCount() == 1) {
		renderer.setSeriesPaint(0, Color.RED);
		renderer.setSeriesFillPaint(0, Color.RED);
	} else {
		for (int i = 0; i < dataset.getRowCount(); i++) {
			Color color = getColorProvider(true).getPointColor((double) i / (double) (dataset.getRowCount() - 1));
			renderer.setSeriesPaint(i, color);
			renderer.setSeriesFillPaint(i, color);
		}
	}
	renderer.setBarPainter(new RapidBarPainter());
	renderer.setDrawBarOutline(true);
	plot.setRenderer(renderer);

	// rotate labels
	if (isLabelRotating()) {
		plot.getDomainAxis().setTickLabelsVisible(true);
		plot.getDomainAxis().setCategoryLabelPositions(
				CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2.0d));
	}

	return chart;
}
 
Example 16
Source File: UserChartController.java    From subsonic with GNU General Public License v3.0 4 votes vote down vote up
private JFreeChart createChart(CategoryDataset dataset, HttpServletRequest request) {
    JFreeChart chart = ChartFactory.createBarChart(null, null, null, dataset, PlotOrientation.HORIZONTAL, false, false, false);

    CategoryPlot plot = chart.getCategoryPlot();
    Paint background = new GradientPaint(0, 0, Color.lightGray, 0, IMAGE_MIN_HEIGHT, Color.white);
    plot.setBackgroundPaint(background);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    LogarithmicAxis rangeAxis = new LogarithmicAxis(null);
    rangeAxis.setStrictValuesFlag(false);
    rangeAxis.setAllowNegativesFlag(true);
    plot.setRangeAxis(rangeAxis);

    // Disable bar outlines.
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    // Set up gradient paint for series.
    GradientPaint gp0 = new GradientPaint(
            0.0f, 0.0f, Color.blue,
            0.0f, 0.0f, new Color(0, 0, 64)
    );
    renderer.setSeriesPaint(0, gp0);

    // Rotate labels.
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));

    // Set theme-specific colors.
    Color bgColor = getBackground(request);
    Color fgColor = getForeground(request);

    chart.setBackgroundPaint(bgColor);

    domainAxis.setTickLabelPaint(fgColor);
    domainAxis.setTickMarkPaint(fgColor);
    domainAxis.setAxisLinePaint(fgColor);

    rangeAxis.setTickLabelPaint(fgColor);
    rangeAxis.setTickMarkPaint(fgColor);
    rangeAxis.setAxisLinePaint(fgColor);

    return chart;
}
 
Example 17
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 18
Source File: BarChartDemo1.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a sample chart.
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
private static JFreeChart createChart(CategoryDataset dataset) {
    
    // create the chart...
    JFreeChart chart = ChartFactory.createBarChart(
        "Bar Chart Demo 1",       // chart title
        "Category",               // domain axis label
        "Value",                  // range axis label
        dataset,                  // data
        PlotOrientation.VERTICAL, // orientation
        true,                     // include legend
        true,                     // tooltips?
        false                     // URLs?
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

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

    // get a reference to the plot for further customisation...
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);

    // ******************************************************************
    //  More than 150 demo applications are included with the JFreeChart
    //  Developer Guide...for more information, see:
    //
    //  >   http://www.object-refinery.com/jfreechart/guide.html
    //
    // ******************************************************************
    
    // set the range axis to display integers only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // disable bar outlines...
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);
    
    // set up gradient paints for series...
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 
            0.0f, 0.0f, new Color(0, 0, 64));
    GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 
            0.0f, 0.0f, new Color(0, 64, 0));
    GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 
            0.0f, 0.0f, new Color(64, 0, 0));
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(
            CategoryLabelPositions.createUpRotationLabelPositions(
                    Math.PI / 6.0));
    // OPTIONAL CUSTOMISATION COMPLETED.
    
    return chart;
    
}
 
Example 19
Source File: BarChartCustomizer.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void customize(JFreeChart chart, JRChart jasperChart)
{
	BarRenderer renderer = (BarRenderer) chart.getCategoryPlot().getRenderer();
	renderer.setSeriesPaint(0, Color.green);
	renderer.setSeriesPaint(1, Color.orange);
}
 
Example 20
Source File: UserChartController.java    From airsonic with GNU General Public License v3.0 4 votes vote down vote up
private JFreeChart createChart(CategoryDataset dataset, HttpServletRequest request) {
    JFreeChart chart = ChartFactory.createBarChart(null, null, null, dataset, PlotOrientation.HORIZONTAL, false, false, false);

    CategoryPlot plot = chart.getCategoryPlot();
    Paint background = new GradientPaint(0, 0, Color.lightGray, 0, IMAGE_MIN_HEIGHT, Color.white);
    plot.setBackgroundPaint(background);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    LogarithmicAxis rangeAxis = new LogarithmicAxis(null);
    rangeAxis.setStrictValuesFlag(false);
    rangeAxis.setAllowNegativesFlag(true);
    plot.setRangeAxis(rangeAxis);

    // Disable bar outlines.
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    // Set up gradient paint for series.
    GradientPaint gp0 = new GradientPaint(
            0.0f, 0.0f, Color.blue,
            0.0f, 0.0f, new Color(0, 0, 64)
    );
    renderer.setSeriesPaint(0, gp0);

    // Rotate labels.
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));

    // Set theme-specific colors.
    Color bgColor = getBackground(request);
    Color fgColor = getForeground(request);

    chart.setBackgroundPaint(bgColor);

    domainAxis.setTickLabelPaint(fgColor);
    domainAxis.setTickMarkPaint(fgColor);
    domainAxis.setAxisLinePaint(fgColor);

    rangeAxis.setTickLabelPaint(fgColor);
    rangeAxis.setTickMarkPaint(fgColor);
    rangeAxis.setAxisLinePaint(fgColor);

    return chart;
}