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

The following examples show how to use org.jfree.chart.renderer.category.BarRenderer#setBarPainter() . 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: 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 2
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 3
Source File: ChartFormatter.java    From nmonvisualizer with Apache License 2.0 5 votes vote down vote up
void formatRenderer(BarRenderer renderer) {
    renderer.setShadowVisible(false);
    renderer.setDrawBarOutline(false);
    renderer.setBarPainter(new GradientPainters.GradientBarPainter());

    renderer.setBaseOutlineStroke(OUTLINE_STROKE);
    renderer.setBaseOutlinePaint(OUTLINE_COLOR);
}
 
Example 4
Source File: StandardChartTheme.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Applies the settings of this theme to the specified renderer.
 *
 * @param renderer  the renderer (<code>null</code> not permitted).
 */
protected void applyToCategoryItemRenderer(CategoryItemRenderer renderer) {
    ParamChecks.nullNotPermitted(renderer, "renderer");

    if (renderer instanceof AbstractRenderer) {
        applyToAbstractRenderer((AbstractRenderer) renderer);
    }

    renderer.setBaseItemLabelFont(this.regularFont);
    renderer.setBaseItemLabelPaint(this.itemLabelPaint);

    // now we handle some special cases - yes, UGLY code alert!

    // BarRenderer
    if (renderer instanceof BarRenderer) {
        BarRenderer br = (BarRenderer) renderer;
        br.setBarPainter(this.barPainter);
        br.setShadowVisible(this.shadowVisible);
        br.setShadowPaint(this.shadowPaint);
    }

    // BarRenderer3D
    if (renderer instanceof BarRenderer3D) {
        BarRenderer3D br3d = (BarRenderer3D) renderer;
        br3d.setWallPaint(this.wallPaint);
    }

    // LineRenderer3D
    if (renderer instanceof LineRenderer3D) {
        LineRenderer3D lr3d = (LineRenderer3D) renderer;
        lr3d.setWallPaint(this.wallPaint);
    }

    //  StatisticalBarRenderer
    if (renderer instanceof StatisticalBarRenderer) {
        StatisticalBarRenderer sbr = (StatisticalBarRenderer) renderer;
        sbr.setErrorIndicatorPaint(this.errorIndicatorPaint);
    }

    // MinMaxCategoryRenderer
    if (renderer instanceof MinMaxCategoryRenderer) {
        MinMaxCategoryRenderer mmcr = (MinMaxCategoryRenderer) renderer;
        mmcr.setGroupPaint(this.errorIndicatorPaint);
    }
}
 
Example 5
Source File: SWTBarChartDemo1.java    From openstock with GNU General Public License v3.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(
        "SWTBarChartDemo1",       // 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...

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

    // 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);

    // the SWTGraphics2D class doesn't handle GradientPaint well, so
    // replace the gradient painter from the default theme with a
    // standard painter...
    renderer.setBarPainter(new StandardBarPainter());

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

    return chart;

}
 
Example 6
Source File: SWTBarChartDemo1.java    From buffer_bci with GNU General Public License v3.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(
        "SWTBarChartDemo1",       // 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...

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

    // 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);

    // the SWTGraphics2D class doesn't handle GradientPaint well, so
    // replace the gradient painter from the default theme with a
    // standard painter...
    renderer.setBarPainter(new StandardBarPainter());

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

    return chart;

}
 
Example 7
Source File: StandardChartTheme.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Applies the settings of this theme to the specified renderer.
 *
 * @param renderer  the renderer (<code>null</code> not permitted).
 */
protected void applyToCategoryItemRenderer(CategoryItemRenderer renderer) {
    if (renderer == null) {
        throw new IllegalArgumentException("Null 'renderer' argument.");
    }

    if (renderer instanceof AbstractRenderer) {
        applyToAbstractRenderer((AbstractRenderer) renderer);
    }

    renderer.setBaseItemLabelFont(this.regularFont);
    renderer.setBaseItemLabelPaint(this.itemLabelPaint);

    // now we handle some special cases - yes, UGLY code alert!

    // BarRenderer
    if (renderer instanceof BarRenderer) {
        BarRenderer br = (BarRenderer) renderer;
        br.setBarPainter(this.barPainter);
        br.setShadowVisible(this.shadowVisible);
        br.setShadowPaint(this.shadowPaint);
    }

    // BarRenderer3D
    if (renderer instanceof BarRenderer3D) {
        BarRenderer3D br3d = (BarRenderer3D) renderer;
        br3d.setWallPaint(this.wallPaint);
    }

    // LineRenderer3D
    if (renderer instanceof LineRenderer3D) {
        LineRenderer3D lr3d = (LineRenderer3D) renderer;
        lr3d.setWallPaint(this.wallPaint);
    }

    //  StatisticalBarRenderer
    if (renderer instanceof StatisticalBarRenderer) {
        StatisticalBarRenderer sbr = (StatisticalBarRenderer) renderer;
        sbr.setErrorIndicatorPaint(this.errorIndicatorPaint);
    }

    // MinMaxCategoryRenderer
    if (renderer instanceof MinMaxCategoryRenderer) {
        MinMaxCategoryRenderer mmcr = (MinMaxCategoryRenderer) renderer;
        mmcr.setGroupPaint(this.errorIndicatorPaint);
    }
}
 
Example 8
Source File: BarRendererTests.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Test that the equals() method distinguishes all fields.
 */
public void testEquals() {
    BarRenderer r1 = new BarRenderer();
    BarRenderer r2 = new BarRenderer();
    assertTrue(r1.equals(r2));
    assertTrue(r2.equals(r1));

    // base value
    r1.setBase(0.123);
    assertFalse(r1.equals(r2));
    r2.setBase(0.123);
    assertTrue(r1.equals(r2));

    // itemMargin
    r1.setItemMargin(0.22);
    assertFalse(r1.equals(r2));
    r2.setItemMargin(0.22);
    assertTrue(r1.equals(r2));

    // drawBarOutline
    r1.setDrawBarOutline(!r1.isDrawBarOutline());
    assertFalse(r1.equals(r2));
    r2.setDrawBarOutline(!r2.isDrawBarOutline());
    assertTrue(r1.equals(r2));

    // maximumBarWidth
    r1.setMaximumBarWidth(0.11);
    assertFalse(r1.equals(r2));
    r2.setMaximumBarWidth(0.11);
    assertTrue(r1.equals(r2));

    // minimumBarLength
    r1.setMinimumBarLength(0.04);
    assertFalse(r1.equals(r2));
    r2.setMinimumBarLength(0.04);
    assertTrue(r1.equals(r2));

    // gradientPaintTransformer
    r1.setGradientPaintTransformer(new StandardGradientPaintTransformer(
            GradientPaintTransformType.CENTER_VERTICAL));
    assertFalse(r1.equals(r2));
    r2.setGradientPaintTransformer(new StandardGradientPaintTransformer(
            GradientPaintTransformType.CENTER_VERTICAL));
    assertTrue(r1.equals(r2));

    // positiveItemLabelPositionFallback
    r1.setPositiveItemLabelPositionFallback(new ItemLabelPosition(
            ItemLabelAnchor.INSIDE1, TextAnchor.CENTER));
    assertFalse(r1.equals(r2));
    r2.setPositiveItemLabelPositionFallback(new ItemLabelPosition(
            ItemLabelAnchor.INSIDE1, TextAnchor.CENTER));
    assertTrue(r1.equals(r2));

    // negativeItemLabelPositionFallback
    r1.setNegativeItemLabelPositionFallback(new ItemLabelPosition(
            ItemLabelAnchor.INSIDE1, TextAnchor.CENTER));
    assertFalse(r1.equals(r2));
    r2.setNegativeItemLabelPositionFallback(new ItemLabelPosition(
            ItemLabelAnchor.INSIDE1, TextAnchor.CENTER));
    assertTrue(r1.equals(r2));

    // barPainter
    r1.setBarPainter(new GradientBarPainter(0.1, 0.2, 0.3));
    assertFalse(r1.equals(r2));
    r2.setBarPainter(new GradientBarPainter(0.1, 0.2, 0.3));
    assertTrue(r1.equals(r2));

    // shadowsVisible
    r1.setShadowVisible(false);
    assertFalse(r1.equals(r2));
    r2.setShadowVisible(false);
    assertTrue(r1.equals(r2));

    r1.setShadowPaint(Color.red);
    assertFalse(r1.equals(r2));
    r2.setShadowPaint(Color.red);
    assertTrue(r1.equals(r2));

    // shadowXOffset
    r1.setShadowXOffset(3.3);
    assertFalse(r1.equals(r2));
    r2.setShadowXOffset(3.3);
    assertTrue(r1.equals(r2));

    // shadowYOffset
    r1.setShadowYOffset(3.3);
    assertFalse(r1.equals(r2));
    r2.setShadowYOffset(3.3);
    assertTrue(r1.equals(r2));

}
 
Example 9
Source File: SWTBarChartDemo1.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(
        "SWTBarChartDemo1",       // 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...

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

    // 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);

    // the SWTGraphics2D class doesn't handle GradientPaint well, so
    // replace the gradient painter from the default theme with a
    // standard painter...
    renderer.setBarPainter(new StandardBarPainter());

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

    return chart;

}
 
Example 10
Source File: StandardChartTheme.java    From ECG-Viewer with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Applies the settings of this theme to the specified renderer.
 *
 * @param renderer  the renderer (<code>null</code> not permitted).
 */
protected void applyToCategoryItemRenderer(CategoryItemRenderer renderer) {
    ParamChecks.nullNotPermitted(renderer, "renderer");

    if (renderer instanceof AbstractRenderer) {
        applyToAbstractRenderer((AbstractRenderer) renderer);
    }

    renderer.setBaseItemLabelFont(this.regularFont);
    renderer.setBaseItemLabelPaint(this.itemLabelPaint);

    // now we handle some special cases - yes, UGLY code alert!

    // BarRenderer
    if (renderer instanceof BarRenderer) {
        BarRenderer br = (BarRenderer) renderer;
        br.setBarPainter(this.barPainter);
        br.setShadowVisible(this.shadowVisible);
        br.setShadowPaint(this.shadowPaint);
    }

    // BarRenderer3D
    if (renderer instanceof BarRenderer3D) {
        BarRenderer3D br3d = (BarRenderer3D) renderer;
        br3d.setWallPaint(this.wallPaint);
    }

    // LineRenderer3D
    if (renderer instanceof LineRenderer3D) {
        LineRenderer3D lr3d = (LineRenderer3D) renderer;
        lr3d.setWallPaint(this.wallPaint);
    }

    //  StatisticalBarRenderer
    if (renderer instanceof StatisticalBarRenderer) {
        StatisticalBarRenderer sbr = (StatisticalBarRenderer) renderer;
        sbr.setErrorIndicatorPaint(this.errorIndicatorPaint);
    }

    // MinMaxCategoryRenderer
    if (renderer instanceof MinMaxCategoryRenderer) {
        MinMaxCategoryRenderer mmcr = (MinMaxCategoryRenderer) renderer;
        mmcr.setGroupPaint(this.errorIndicatorPaint);
    }
}
 
Example 11
Source File: SWTBarChartDemo1.java    From ECG-Viewer 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(
        "SWTBarChartDemo1",       // 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...

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

    // 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);

    // the SWTGraphics2D class doesn't handle GradientPaint well, so
    // replace the gradient painter from the default theme with a
    // standard painter...
    renderer.setBarPainter(new StandardBarPainter());

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

    return chart;

}
 
Example 12
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 13
Source File: StandardChartTheme.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Applies the settings of this theme to the specified renderer.
 *
 * @param renderer  the renderer (<code>null</code> not permitted).
 */
protected void applyToCategoryItemRenderer(CategoryItemRenderer renderer) {
    ParamChecks.nullNotPermitted(renderer, "renderer");

    if (renderer instanceof AbstractRenderer) {
        applyToAbstractRenderer((AbstractRenderer) renderer);
    }

    renderer.setBaseItemLabelFont(this.regularFont);
    renderer.setBaseItemLabelPaint(this.itemLabelPaint);

    // now we handle some special cases - yes, UGLY code alert!

    // BarRenderer
    if (renderer instanceof BarRenderer) {
        BarRenderer br = (BarRenderer) renderer;
        br.setBarPainter(this.barPainter);
        br.setShadowVisible(this.shadowVisible);
        br.setShadowPaint(this.shadowPaint);
    }

    // BarRenderer3D
    if (renderer instanceof BarRenderer3D) {
        BarRenderer3D br3d = (BarRenderer3D) renderer;
        br3d.setWallPaint(this.wallPaint);
    }

    // LineRenderer3D
    if (renderer instanceof LineRenderer3D) {
        LineRenderer3D lr3d = (LineRenderer3D) renderer;
        lr3d.setWallPaint(this.wallPaint);
    }

    //  StatisticalBarRenderer
    if (renderer instanceof StatisticalBarRenderer) {
        StatisticalBarRenderer sbr = (StatisticalBarRenderer) renderer;
        sbr.setErrorIndicatorPaint(this.errorIndicatorPaint);
    }

    // MinMaxCategoryRenderer
    if (renderer instanceof MinMaxCategoryRenderer) {
        MinMaxCategoryRenderer mmcr = (MinMaxCategoryRenderer) renderer;
        mmcr.setGroupPaint(this.errorIndicatorPaint);
    }
}
 
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: StandardChartTheme.java    From SIMVA-SoS with Apache License 2.0 4 votes vote down vote up
/**
 * Applies the settings of this theme to the specified renderer.
 *
 * @param renderer  the renderer (<code>null</code> not permitted).
 */
protected void applyToCategoryItemRenderer(CategoryItemRenderer renderer) {
    ParamChecks.nullNotPermitted(renderer, "renderer");

    if (renderer instanceof AbstractRenderer) {
        applyToAbstractRenderer((AbstractRenderer) renderer);
    }

    renderer.setBaseItemLabelFont(this.regularFont);
    renderer.setBaseItemLabelPaint(this.itemLabelPaint);

    // now we handle some special cases - yes, UGLY code alert!

    // BarRenderer
    if (renderer instanceof BarRenderer) {
        BarRenderer br = (BarRenderer) renderer;
        br.setBarPainter(this.barPainter);
        br.setShadowVisible(this.shadowVisible);
        br.setShadowPaint(this.shadowPaint);
    }

    // BarRenderer3D
    if (renderer instanceof BarRenderer3D) {
        BarRenderer3D br3d = (BarRenderer3D) renderer;
        br3d.setWallPaint(this.wallPaint);
    }

    // LineRenderer3D
    if (renderer instanceof LineRenderer3D) {
        LineRenderer3D lr3d = (LineRenderer3D) renderer;
        lr3d.setWallPaint(this.wallPaint);
    }

    //  StatisticalBarRenderer
    if (renderer instanceof StatisticalBarRenderer) {
        StatisticalBarRenderer sbr = (StatisticalBarRenderer) renderer;
        sbr.setErrorIndicatorPaint(this.errorIndicatorPaint);
    }

    // MinMaxCategoryRenderer
    if (renderer instanceof MinMaxCategoryRenderer) {
        MinMaxCategoryRenderer mmcr = (MinMaxCategoryRenderer) renderer;
        mmcr.setGroupPaint(this.errorIndicatorPaint);
    }
}
 
Example 17
Source File: SWTBarChartDemo1.java    From SIMVA-SoS with Apache License 2.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(
        "SWTBarChartDemo1",       // 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...

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

    // 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);

    // the SWTGraphics2D class doesn't handle GradientPaint well, so
    // replace the gradient painter from the default theme with a
    // standard painter...
    renderer.setBarPainter(new StandardBarPainter());

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

    return chart;

}
 
Example 18
Source File: StandardChartTheme.java    From ccu-historian with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Applies the settings of this theme to the specified renderer.
 *
 * @param renderer  the renderer (<code>null</code> not permitted).
 */
protected void applyToCategoryItemRenderer(CategoryItemRenderer renderer) {
    ParamChecks.nullNotPermitted(renderer, "renderer");

    if (renderer instanceof AbstractRenderer) {
        applyToAbstractRenderer((AbstractRenderer) renderer);
    }

    renderer.setBaseItemLabelFont(this.regularFont);
    renderer.setBaseItemLabelPaint(this.itemLabelPaint);

    // now we handle some special cases - yes, UGLY code alert!

    // BarRenderer
    if (renderer instanceof BarRenderer) {
        BarRenderer br = (BarRenderer) renderer;
        br.setBarPainter(this.barPainter);
        br.setShadowVisible(this.shadowVisible);
        br.setShadowPaint(this.shadowPaint);
    }

    // BarRenderer3D
    if (renderer instanceof BarRenderer3D) {
        BarRenderer3D br3d = (BarRenderer3D) renderer;
        br3d.setWallPaint(this.wallPaint);
    }

    // LineRenderer3D
    if (renderer instanceof LineRenderer3D) {
        LineRenderer3D lr3d = (LineRenderer3D) renderer;
        lr3d.setWallPaint(this.wallPaint);
    }

    //  StatisticalBarRenderer
    if (renderer instanceof StatisticalBarRenderer) {
        StatisticalBarRenderer sbr = (StatisticalBarRenderer) renderer;
        sbr.setErrorIndicatorPaint(this.errorIndicatorPaint);
    }

    // MinMaxCategoryRenderer
    if (renderer instanceof MinMaxCategoryRenderer) {
        MinMaxCategoryRenderer mmcr = (MinMaxCategoryRenderer) renderer;
        mmcr.setGroupPaint(this.errorIndicatorPaint);
    }
}
 
Example 19
Source File: SWTBarChartDemo1.java    From ccu-historian with GNU General Public License v3.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(
        "SWTBarChartDemo1",       // 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...

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

    // 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);

    // the SWTGraphics2D class doesn't handle GradientPaint well, so
    // replace the gradient painter from the default theme with a
    // standard painter...
    renderer.setBarPainter(new StandardBarPainter());

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

    return chart;

}
 
Example 20
Source File: StandardChartTheme.java    From openstock with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Applies the settings of this theme to the specified renderer.
 *
 * @param renderer  the renderer (<code>null</code> not permitted).
 */
protected void applyToCategoryItemRenderer(CategoryItemRenderer renderer) {
    ParamChecks.nullNotPermitted(renderer, "renderer");

    if (renderer instanceof AbstractRenderer) {
        applyToAbstractRenderer((AbstractRenderer) renderer);
    }

    renderer.setBaseItemLabelFont(this.regularFont);
    renderer.setBaseItemLabelPaint(this.itemLabelPaint);

    // now we handle some special cases - yes, UGLY code alert!

    // BarRenderer
    if (renderer instanceof BarRenderer) {
        BarRenderer br = (BarRenderer) renderer;
        br.setBarPainter(this.barPainter);
        br.setShadowVisible(this.shadowVisible);
        br.setShadowPaint(this.shadowPaint);
    }

    // BarRenderer3D
    if (renderer instanceof BarRenderer3D) {
        BarRenderer3D br3d = (BarRenderer3D) renderer;
        br3d.setWallPaint(this.wallPaint);
    }

    // LineRenderer3D
    if (renderer instanceof LineRenderer3D) {
        LineRenderer3D lr3d = (LineRenderer3D) renderer;
        lr3d.setWallPaint(this.wallPaint);
    }

    //  StatisticalBarRenderer
    if (renderer instanceof StatisticalBarRenderer) {
        StatisticalBarRenderer sbr = (StatisticalBarRenderer) renderer;
        sbr.setErrorIndicatorPaint(this.errorIndicatorPaint);
    }

    // MinMaxCategoryRenderer
    if (renderer instanceof MinMaxCategoryRenderer) {
        MinMaxCategoryRenderer mmcr = (MinMaxCategoryRenderer) renderer;
        mmcr.setGroupPaint(this.errorIndicatorPaint);
    }
}