Java Code Examples for org.jfree.chart.plot.CategoryPlot#setRenderer()

The following examples show how to use org.jfree.chart.plot.CategoryPlot#setRenderer() . 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: AbstractCategoryItemRendererTest.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * A test that reproduces the problem reported in bug 2947660.
 */
@Test
public void test2947660() {
    AbstractCategoryItemRenderer r = new LineAndShapeRenderer();
    assertNotNull(r.getLegendItems());
    assertEquals(0, r.getLegendItems().getItemCount());

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    CategoryPlot plot = new CategoryPlot();
    plot.setDataset(dataset);
    plot.setRenderer(r);
    assertEquals(0, r.getLegendItems().getItemCount());

    dataset.addValue(1.0, "S1", "C1");
    LegendItemCollection lic = r.getLegendItems();
    assertEquals(1, lic.getItemCount());
    assertEquals("S1", lic.get(0).getLabel());
}
 
Example 2
Source File: CategoryPlotTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * A test for bug 1654215 (where a renderer is added to the plot without
 * a corresponding dataset and it throws an exception at drawing time).
 */
public void test1654215() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    JFreeChart chart = ChartFactory.createLineChart("Title", "X", "Y",
            dataset, true);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setRenderer(1, new LineAndShapeRenderer());
    boolean success = false;
    try {
        BufferedImage image = new BufferedImage(200 , 100,
                BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = image.createGraphics();
        chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null);
        g2.dispose();
        success = true;
    }
    catch (Exception e) {
        e.printStackTrace();
        success = false;
    }
    assertTrue(success);
}
 
Example 3
Source File: ChartImageGenerator.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private JFreeChart getStackedBarChart( final Visualization visualization, CategoryDataset dataSet, boolean horizontal )
{
    JFreeChart stackedBarChart = ChartFactory.createStackedBarChart( visualization.getName(), visualization.getDomainAxisLabel(),
        visualization.getRangeAxisLabel(), dataSet, PlotOrientation.VERTICAL, !visualization.isHideLegend(), false, false );

    setBasicConfig( stackedBarChart, visualization );

    CategoryPlot plot = (CategoryPlot) stackedBarChart.getPlot();
    plot.setOrientation( horizontal ? PlotOrientation.HORIZONTAL : PlotOrientation.VERTICAL );
    plot.setRenderer( getStackedBarRenderer() );

    CategoryAxis xAxis = plot.getDomainAxis();
    xAxis.setCategoryLabelPositions( CategoryLabelPositions.UP_45 );

    return stackedBarChart;
}
 
Example 4
Source File: ChartImageGenerator.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private JFreeChart getStackedAreaChart( final Visualization visualization, CategoryDataset dataSet )
{
    JFreeChart stackedAreaChart = ChartFactory.createStackedAreaChart( visualization.getName(), visualization.getDomainAxisLabel(),
        visualization.getRangeAxisLabel(), dataSet, PlotOrientation.VERTICAL, !visualization.isHideLegend(), false, false );

    setBasicConfig( stackedAreaChart, visualization );

    CategoryPlot plot = (CategoryPlot) stackedAreaChart.getPlot();
    plot.setOrientation( PlotOrientation.VERTICAL );
    plot.setRenderer( getStackedAreaRenderer() );

    CategoryAxis xAxis = plot.getDomainAxis();
    xAxis.setCategoryLabelPositions( CategoryLabelPositions.UP_45 );
    xAxis.setLabelFont( LABEL_FONT );

    return stackedAreaChart;
}
 
Example 5
Source File: DefaultChartService.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private JFreeChart getStackedAreaChart( BaseChart chart, CategoryDataset dataSet )
{
    JFreeChart stackedAreaChart = ChartFactory.createStackedAreaChart( chart.getName(), chart.getDomainAxisLabel(),
        chart.getRangeAxisLabel(), dataSet, PlotOrientation.VERTICAL, !chart.isHideLegend(), false, false );

    setBasicConfig( stackedAreaChart, chart );

    CategoryPlot plot = (CategoryPlot) stackedAreaChart.getPlot();
    plot.setOrientation( PlotOrientation.VERTICAL );
    plot.setRenderer( getStackedAreaRenderer() );

    CategoryAxis xAxis = plot.getDomainAxis();
    xAxis.setCategoryLabelPositions( CategoryLabelPositions.UP_45 );
    xAxis.setLabelFont( LABEL_FONT );

    return stackedAreaChart;
}
 
Example 6
Source File: AbstractCategoryItemRendererTest.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * A test that reproduces the problem reported in bug 2947660.
 */
@Test
public void test2947660() {
    AbstractCategoryItemRenderer r = new LineAndShapeRenderer();
    assertNotNull(r.getLegendItems());
    assertEquals(0, r.getLegendItems().getItemCount());

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    CategoryPlot plot = new CategoryPlot();
    plot.setDataset(dataset);
    plot.setRenderer(r);
    assertEquals(0, r.getLegendItems().getItemCount());

    dataset.addValue(1.0, "S1", "C1");
    LegendItemCollection lic = r.getLegendItems();
    assertEquals(1, lic.getItemCount());
    assertEquals("S1", lic.get(0).getLabel());
}
 
Example 7
Source File: AbstractCategoryItemRendererTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * A test that reproduces the problem reported in bug 2947660.
 */
public void test2947660() {
    AbstractCategoryItemRenderer r = new LineAndShapeRenderer();
    assertNotNull(r.getLegendItems());
    assertEquals(0, r.getLegendItems().getItemCount());

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    CategoryPlot plot = new CategoryPlot();
    plot.setDataset(dataset);
    plot.setRenderer(r);
    assertEquals(0, r.getLegendItems().getItemCount());

    dataset.addValue(1.0, "S1", "C1");
    LegendItemCollection lic = r.getLegendItems();
    assertEquals(1, lic.getItemCount());
    assertEquals("S1", lic.get(0).getLabel());
}
 
Example 8
Source File: AbstractCategoryItemRendererTest.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * A test that reproduces the problem reported in bug 2947660.
 */
@Test
public void test2947660() {
    AbstractCategoryItemRenderer r = new LineAndShapeRenderer();
    assertNotNull(r.getLegendItems());
    assertEquals(0, r.getLegendItems().getItemCount());

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    CategoryPlot plot = new CategoryPlot();
    plot.setDataset(dataset);
    plot.setRenderer(r);
    assertEquals(0, r.getLegendItems().getItemCount());

    dataset.addValue(1.0, "S1", "C1");
    LegendItemCollection lic = r.getLegendItems();
    assertEquals(1, lic.getItemCount());
    assertEquals("S1", lic.get(0).getLabel());
}
 
Example 9
Source File: AbstractCategoryItemRendererTest.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * A test that reproduces the problem reported in bug 2947660.
 */
@Test
public void test2947660() {
    AbstractCategoryItemRenderer r = new LineAndShapeRenderer();
    assertNotNull(r.getLegendItems());
    assertEquals(0, r.getLegendItems().getItemCount());

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    CategoryPlot plot = new CategoryPlot();
    plot.setDataset(dataset);
    plot.setRenderer(r);
    assertEquals(0, r.getLegendItems().getItemCount());

    dataset.addValue(1.0, "S1", "C1");
    LegendItemCollection lic = r.getLegendItems();
    assertEquals(1, lic.getItemCount());
    assertEquals("S1", lic.get(0).getLabel());
}
 
Example 10
Source File: CategoryPlotTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * A test for a bug where setting the renderer doesn't register the plot
 * as a RendererChangeListener.
 */
public void testSetRenderer() {
    CategoryPlot plot = new CategoryPlot();
    CategoryItemRenderer renderer = new LineAndShapeRenderer();
    plot.setRenderer(renderer);
    // now make a change to the renderer and see if it triggers a plot
    // change event...
    MyPlotChangeListener listener = new MyPlotChangeListener();
    plot.addChangeListener(listener);
    renderer.setSeriesPaint(0, Color.black);
    assertTrue(listener.getEvent() != null);
}
 
Example 11
Source File: CategoryPlotTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * A test for bug report 1169972.
 */
public void test1169972() {
    CategoryPlot plot = new CategoryPlot(null, null, null, null);
    plot.setDomainAxis(new CategoryAxis("C"));
    plot.setRangeAxis(new NumberAxis("Y"));
    plot.setRenderer(new BarRenderer());
    plot.setDataset(new DefaultCategoryDataset());
    assertTrue(plot != null);
}
 
Example 12
Source File: CommonBarChartAction.java    From bamboobsc with Apache License 2.0 5 votes vote down vote up
private void setPlotColor(CategoryPlot plot, List<String> names, List<String> colors) throws Exception {
   	Paint[] paints = new Paint[colors.size()];
   	for (int ix=0; ix<names.size(); ix++) {
   		paints[ix] = Color.decode(colors.get(ix));
   	}
   	CategoryItemRenderer renderer = new CustomRenderer(paints);
   	plot.setRenderer(renderer);
}
 
Example 13
Source File: CategoryPlotTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * A test for a bug where setting the renderer doesn't register the plot
 * as a RendererChangeListener.
 */
public void testSetRenderer() {
    CategoryPlot plot = new CategoryPlot();
    CategoryItemRenderer renderer = new LineAndShapeRenderer();
    plot.setRenderer(renderer);
    // now make a change to the renderer and see if it triggers a plot
    // change event...
    MyPlotChangeListener listener = new MyPlotChangeListener();
    plot.addChangeListener(listener);
    renderer.setSeriesPaint(0, Color.black);
    assertTrue(listener.getEvent() != null);
}
 
Example 14
Source File: GenericChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected JFreeChart createBar3DChart() throws JRException 
	{
		ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
		JFreeChart jfreeChart =
			ChartFactory.createBarChart3D(
					evaluateTextExpression(getChart().getTitleExpression()),
					evaluateTextExpression(((JRBar3DPlot)getPlot()).getCategoryAxisLabelExpression()),
					evaluateTextExpression(((JRBar3DPlot)getPlot()).getValueAxisLabelExpression()),
					(CategoryDataset)getDataset(),
					getPlot().getOrientationValue().getOrientation(),
					isShowLegend(),
					true,
					false );

		configureChart(jfreeChart, getPlot());

		CategoryPlot categoryPlot = (CategoryPlot)jfreeChart.getPlot();
		JRBar3DPlot bar3DPlot = (JRBar3DPlot)getPlot();

		BarRenderer3D barRenderer3D =
			new BarRenderer3D(
				bar3DPlot.getXOffsetDouble() == null ? BarRenderer3D.DEFAULT_X_OFFSET : bar3DPlot.getXOffsetDouble(),
				bar3DPlot.getYOffsetDouble() == null ? BarRenderer3D.DEFAULT_Y_OFFSET : bar3DPlot.getYOffsetDouble()
				);

		boolean isShowLabels = bar3DPlot.getShowLabels() == null ? false : bar3DPlot.getShowLabels();
		barRenderer3D.setBaseItemLabelsVisible( isShowLabels );
		if (isShowLabels)
		{
			JRItemLabel itemLabel = bar3DPlot.getItemLabel();
			Integer baseFontSize = (Integer)getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.BASEFONT_SIZE);
			JRFont font = itemLabel != null && itemLabel.getFont() != null ? itemLabel.getFont() : null;
			barRenderer3D.setBaseItemLabelFont(getFont(new JRBaseFont(getChart(), null), font, baseFontSize));
			
			if (itemLabel != null)
			{
				if (itemLabel.getColor() != null)
				{
					barRenderer3D.setBaseItemLabelPaint(itemLabel.getColor());
				}
				else
				{
					barRenderer3D.setBaseItemLabelPaint(getChart().getForecolor());
				}
//				categoryRenderer.setBaseFillPaint(itemLabel.getBackgroundColor());
//				if (itemLabel.getMask() != null)
//				{
//					barRenderer3D.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator(
//							StandardCategoryItemLabelGenerator.DEFAULT_LABEL_FORMAT_STRING, 
//							new DecimalFormat(itemLabel.getMask())));
//				}
//				else
//				{
					barRenderer3D.setBaseItemLabelGenerator((CategoryItemLabelGenerator)getLabelGenerator());
//				}
			}
			else
			{
				barRenderer3D.setBaseItemLabelGenerator((CategoryItemLabelGenerator)getLabelGenerator());
				barRenderer3D.setBaseItemLabelPaint(getChart().getForecolor());
			}
		}

		categoryPlot.setRenderer(barRenderer3D);
		
		// Handle the axis formating for the category axis
		configureAxis(categoryPlot.getDomainAxis(), bar3DPlot.getCategoryAxisLabelFont(),
				bar3DPlot.getCategoryAxisLabelColor(), bar3DPlot.getCategoryAxisTickLabelFont(),
				bar3DPlot.getCategoryAxisTickLabelColor(), bar3DPlot.getCategoryAxisTickLabelMask(), bar3DPlot.getCategoryAxisVerticalTickLabels(),
				bar3DPlot.getOwnCategoryAxisLineColor(), false,
				(Comparable<?>)evaluateExpression(bar3DPlot.getDomainAxisMinValueExpression()),
				(Comparable<?>)evaluateExpression(bar3DPlot.getDomainAxisMaxValueExpression()));


		// Handle the axis formating for the value axis
		configureAxis(categoryPlot.getRangeAxis(), bar3DPlot.getValueAxisLabelFont(),
				bar3DPlot.getValueAxisLabelColor(), bar3DPlot.getValueAxisTickLabelFont(),
				bar3DPlot.getValueAxisTickLabelColor(), bar3DPlot.getValueAxisTickLabelMask(), bar3DPlot.getValueAxisVerticalTickLabels(),
				bar3DPlot.getOwnValueAxisLineColor(), true,
				(Comparable<?>)evaluateExpression(bar3DPlot.getRangeAxisMinValueExpression()),
				(Comparable<?>)evaluateExpression(bar3DPlot.getRangeAxisMaxValueExpression()));
		
		return jfreeChart;
	}
 
Example 15
Source File: LevelRenderCustomizer.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void customize(JFreeChart jfc, JRChart jrc) 
{
	if (jfc.getPlot() instanceof CategoryPlot)
	{
		CategoryPlot plot = (CategoryPlot)jfc.getPlot();

		ItemsCounter itemsCounter = new CategoryCounter(plot);
		
		Integer seriesIndex = 
			CustomizerUtil.resolveIndex(
				this, 
				itemsCounter,
				new CategorySeriesNameProvider(plot)
				);
		if (seriesIndex != null)
		{
			LevelRenderer levelRenderer = new LevelRenderer();

			Double itemMargin = getDoubleProperty(PROPERTY_ITEM_MARIGN);
			if (itemMargin != null)
			{
				levelRenderer.setItemMargin(itemMargin);
			}
			Double maxItemWidth = getDoubleProperty(PROPERTY_MAX_ITEM_WIDTH);
			if (maxItemWidth != null)
			{
				levelRenderer.setMaximumItemWidth(maxItemWidth);
			}

			if (seriesIndex == -1)
			{
				for (int i = 0; i < itemsCounter.getCount(); i++)
				{
					plot.setRenderer(i, levelRenderer);
				}
			}
			else
			{
				plot.setRenderer(seriesIndex, levelRenderer);
			}
		}
	}
}
 
Example 16
Source File: DefaultChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
	 *
	 */
	protected JFreeChart createStackedBar3DChart() throws JRException
	{
		ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
		JFreeChart jfreeChart =
			ChartFactory.createStackedBarChart3D(
				evaluateTextExpression(getChart().getTitleExpression()),
				evaluateTextExpression(((JRBar3DPlot)getPlot()).getCategoryAxisLabelExpression()),
				evaluateTextExpression(((JRBar3DPlot)getPlot()).getValueAxisLabelExpression()),
				(CategoryDataset)getDataset(),
				getPlot().getOrientationValue().getOrientation(),
				isShowLegend(),
				true,
				false
				);

		configureChart(jfreeChart);

		CategoryPlot categoryPlot = (CategoryPlot)jfreeChart.getPlot();
		JRBar3DPlot bar3DPlot = (JRBar3DPlot)getPlot();

		StackedBarRenderer3D stackedBarRenderer3D =
			new StackedBarRenderer3D(
				bar3DPlot.getXOffsetDouble() == null ? StackedBarRenderer3D.DEFAULT_X_OFFSET : bar3DPlot.getXOffsetDouble(),
				bar3DPlot.getYOffsetDouble() == null ? StackedBarRenderer3D.DEFAULT_Y_OFFSET : bar3DPlot.getYOffsetDouble()
				);
		boolean isShowLabels = bar3DPlot.getShowLabels() == null ? false : bar3DPlot.getShowLabels();
		stackedBarRenderer3D.setBaseItemLabelsVisible(isShowLabels);
		if (isShowLabels)
		{
			JRItemLabel itemLabel = bar3DPlot.getItemLabel();

			stackedBarRenderer3D.setBaseItemLabelFont(
				fontUtil.getAwtFont(
					getFont(itemLabel == null ? null : itemLabel.getFont()), 
					getLocale()
					)
				);
			
			if (itemLabel != null)
			{
				if (itemLabel.getColor() != null)
				{
					stackedBarRenderer3D.setBaseItemLabelPaint(itemLabel.getColor());
				}
				else
				{
					stackedBarRenderer3D.setBaseItemLabelPaint(getChart().getForecolor());
				}
//				categoryRenderer.setBaseFillPaint(itemLabel.getBackgroundColor());
//				if (itemLabel.getMask() != null)
//				{
//					barRenderer3D.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator(
//							StandardCategoryItemLabelGenerator.DEFAULT_LABEL_FORMAT_STRING, 
//							new DecimalFormat(itemLabel.getMask())));
//				}
//				else
//				{
				stackedBarRenderer3D.setBaseItemLabelGenerator((CategoryItemLabelGenerator)getLabelGenerator());
//				}
			}
			else
			{
				stackedBarRenderer3D.setBaseItemLabelGenerator((CategoryItemLabelGenerator)getLabelGenerator());
				stackedBarRenderer3D.setBaseItemLabelPaint(getChart().getForecolor());
			}
		}
		categoryPlot.setRenderer(stackedBarRenderer3D);

		// Handle the axis formating for the category axis
		configureAxis(categoryPlot.getDomainAxis(), bar3DPlot.getCategoryAxisLabelFont(),
				bar3DPlot.getCategoryAxisLabelColor(), bar3DPlot.getCategoryAxisTickLabelFont(),
				bar3DPlot.getCategoryAxisTickLabelColor(), bar3DPlot.getCategoryAxisTickLabelMask(), bar3DPlot.getCategoryAxisVerticalTickLabels(),
				bar3DPlot.getCategoryAxisLineColor(), false,
				(Comparable<?>)evaluateExpression(bar3DPlot.getDomainAxisMinValueExpression()),
				(Comparable<?>)evaluateExpression(bar3DPlot.getDomainAxisMaxValueExpression()));

		// Handle the axis formating for the value axis
		configureAxis(categoryPlot.getRangeAxis(), bar3DPlot.getValueAxisLabelFont(),
				bar3DPlot.getValueAxisLabelColor(), bar3DPlot.getValueAxisTickLabelFont(),
				bar3DPlot.getValueAxisTickLabelColor(), bar3DPlot.getValueAxisTickLabelMask(), bar3DPlot.getValueAxisVerticalTickLabels(),
				bar3DPlot.getValueAxisLineColor(), true,
				(Comparable<?>)evaluateExpression(bar3DPlot.getRangeAxisMinValueExpression()),
				(Comparable<?>)evaluateExpression(bar3DPlot.getRangeAxisMaxValueExpression()));

		return jfreeChart;
	}
 
Example 17
Source File: SimpleChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
	 *
	 */
	protected JFreeChart createStackedBar3DChart() throws JRException
	{
		ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
		JFreeChart jfreeChart =
			ChartFactory.createStackedBarChart3D(
				evaluateTextExpression(getChart().getTitleExpression()),
				evaluateTextExpression(((JRBar3DPlot)getPlot()).getCategoryAxisLabelExpression()),
				evaluateTextExpression(((JRBar3DPlot)getPlot()).getValueAxisLabelExpression()),
				(CategoryDataset)getDataset(),
				getPlot().getOrientationValue().getOrientation(),
				isShowLegend(),
				true,
				false
				);

		configureChart(jfreeChart, getPlot());

		CategoryPlot categoryPlot = (CategoryPlot)jfreeChart.getPlot();
		JRBar3DPlot bar3DPlot = (JRBar3DPlot)getPlot();

		StackedBarRenderer3D stackedBarRenderer3D =
			new StackedBarRenderer3D(
				bar3DPlot.getXOffsetDouble() == null ? StackedBarRenderer3D.DEFAULT_X_OFFSET : bar3DPlot.getXOffsetDouble(),
				bar3DPlot.getYOffsetDouble() == null ? StackedBarRenderer3D.DEFAULT_Y_OFFSET : bar3DPlot.getYOffsetDouble()
				);

		boolean isShowLabels = bar3DPlot.getShowLabels() == null ? false : bar3DPlot.getShowLabels();
		stackedBarRenderer3D.setBaseItemLabelsVisible(isShowLabels);
		if(isShowLabels)
		{
			JRItemLabel itemLabel = bar3DPlot.getItemLabel();

			stackedBarRenderer3D.setBaseItemLabelFont(
					getFontUtil().getAwtFont(
					getFont(itemLabel == null ? null : itemLabel.getFont()), 
					getLocale()
					)
				);
			
			if(itemLabel != null)
			{
				if(itemLabel.getColor() != null)
				{
					stackedBarRenderer3D.setBaseItemLabelPaint(itemLabel.getColor());
				}
				else
				{
					stackedBarRenderer3D.setBaseItemLabelPaint(getChart().getForecolor());
				}
//				categoryRenderer.setBaseFillPaint(itemLabel.getBackgroundColor());
//				if(itemLabel.getMask() != null)
//				{
//					barRenderer3D.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator(
//							StandardCategoryItemLabelGenerator.DEFAULT_LABEL_FORMAT_STRING, 
//							new DecimalFormat(itemLabel.getMask())));
//				}
//				else
//				{
				stackedBarRenderer3D.setBaseItemLabelGenerator((CategoryItemLabelGenerator)getLabelGenerator());
//				}
			}
			else
			{
				stackedBarRenderer3D.setBaseItemLabelGenerator((CategoryItemLabelGenerator)getLabelGenerator());
				stackedBarRenderer3D.setBaseItemLabelPaint(getChart().getForecolor());
			}
		}

		categoryPlot.setRenderer(stackedBarRenderer3D);

		// Handle the axis formating for the category axis
		configureAxis(categoryPlot.getDomainAxis(), bar3DPlot.getCategoryAxisLabelFont(),
				bar3DPlot.getCategoryAxisLabelColor(), bar3DPlot.getCategoryAxisTickLabelFont(),
				bar3DPlot.getCategoryAxisTickLabelColor(), bar3DPlot.getCategoryAxisTickLabelMask(), bar3DPlot.getCategoryAxisVerticalTickLabels(),
				bar3DPlot.getOwnCategoryAxisLineColor(), getDomainAxisSettings(),
				(Comparable<?>)evaluateExpression(bar3DPlot.getDomainAxisMinValueExpression()), 
				(Comparable<?>)evaluateExpression(bar3DPlot.getDomainAxisMaxValueExpression())
				);


		// Handle the axis formating for the value axis
		configureAxis(categoryPlot.getRangeAxis(), bar3DPlot.getValueAxisLabelFont(),
				bar3DPlot.getValueAxisLabelColor(), bar3DPlot.getValueAxisTickLabelFont(),
				bar3DPlot.getValueAxisTickLabelColor(), bar3DPlot.getValueAxisTickLabelMask(), bar3DPlot.getValueAxisVerticalTickLabels(),
				bar3DPlot.getOwnValueAxisLineColor(), getRangeAxisSettings(),
				(Comparable<?>)evaluateExpression(bar3DPlot.getRangeAxisMinValueExpression()), 
				(Comparable<?>)evaluateExpression(bar3DPlot.getRangeAxisMaxValueExpression())
				);

		return jfreeChart;
	}
 
Example 18
Source File: LTMStateGraphPanel.java    From opencards with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public LTMStateGraphPanel() {
        setLayout(new BorderLayout());

        // setup the stacked bar chart
        dataset = new DefaultCategoryDataset();
        final JFreeChart chart = ChartFactory.createStackedBarChart(
                null,  // chart title
                Utils.getRB().getString("CardTableModel.stats.learnsuccess"),                  // domain axis label
//                "# cards",                     // range axis label
                null,                     // range axis label
                dataset,                     // data
                PlotOrientation.VERTICAL,    // the plot orientation
                false,                        // legend
                true,                        // tooltips
                false                        // urls
        );

        StackedBarRenderer renderer = new StackedBarRenderer();
        renderer.setGradientPaintTransformer(new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL));

        renderer.setItemMargin(0.0);
        Paint bluePaint = new GradientPaint(0.0f, 0.0f, new Color(0x22, 0x22, 0xFF), 0.0f, 0.0f, new Color(0x88, 0x88, 0xFF));
        renderer.setSeriesPaint(0, bluePaint);
        renderer.setSeriesToolTipGenerator(0, new StandardCategoryToolTipGenerator());

//        Paint p2 = new GradientPaint(0.0f, 0.0f, new Color(0xFF, 0x22, 0x22), 0.0f, 0.0f, new Color(0xFF, 0x88, 0x88));
//        renderer.setSeriesPaint(1, p2);
//        renderer.setSeriesToolTipGenerator(1, new StandardCategoryToolTipGenerator());
//
//        Paint p3 = new GradientPaint(0.0f, 0.0f, new Color(0x22, 0xFF, 0x22), 0.0f, 0.0f, new Color(0x88, 0xFF, 0x88));
//        renderer.setSeriesPaint(2, p3);
//        renderer.setSeriesToolTipGenerator(2, new StandardCategoryToolTipGenerator());

        CategoryPlot plot = (CategoryPlot) chart.getPlot();
        plot.setRenderer(renderer);
        valueAxis = plot.getRangeAxis();
        TickUnits units = (TickUnits) NumberAxis.createIntegerTickUnits();
        valueAxis.setStandardTickUnits(units);

        ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPopupMenu(null);
        chartPanel.setDomainZoomable(false);
        chartPanel.setRangeZoomable(false);
        add(chartPanel, BorderLayout.CENTER);

        rebuildPanel(new HashSet<CardFile>());

        learnedPerfectly = Utils.getRB().getString("CardTableModel.stats.perfect");
        learnedNotYet = Utils.getRB().getString("CardTableModel.stats.notatall");
        learnedNaJa = Utils.getRB().getString("CardTableModel.stats.well");
    }
 
Example 19
Source File: ServerWideReportManagerImpl.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
private byte[] generateLayeredBarChart (CategoryDataset dataset, int width, int height)
{
	JFreeChart chart = ChartFactory.createBarChart (null, // chart title
			null, // domain axis label
			null, // range axis label
			dataset, // data
			PlotOrientation.VERTICAL, // the plot orientation
			true, // legend
			true, // 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 ();

	// disable bar outlines...
	LayeredBarRenderer renderer = new LayeredBarRenderer ();
	renderer.setDrawBarOutline (false);
	renderer.setSeriesBarWidth (0, .6);
	renderer.setSeriesBarWidth (1, .8);
	renderer.setSeriesBarWidth (2, 1.0);
	plot.setRenderer (renderer);

	// for this renderer, we need to draw the first series last...
	plot.setRowRenderingOrder (SortOrder.DESCENDING);

	// 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 = (CategoryAxis) plot.getDomainAxis ();
	domainAxis.setCategoryLabelPositions (CategoryLabelPositions.DOWN_45);
	domainAxis.setLowerMargin (0.0);
	domainAxis.setUpperMargin (0.0);

	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 20
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;
}