Question

I created the following Pie Chart:

public class MyPieChart extends ChartComposite {

public MyPieChart(Composite parent, int style, CategoryToPieDataset dataset, ProductivityViewCtrl control) {
    super(/* Composite comp */parent,
    /* int style */style,
    /* JFreeChart jfreechart */null,
    /* int width */10,
    /* int height */10,
    /* int minimumDrawW */1,
    /* int minimumDrawH */1,
    /* int maximumDrawW */Integer.MAX_VALUE,
    /* int maximumDrawH */Integer.MAX_VALUE,
    /* boolean usingBuffer */false,
    /* boolean properties */false,
    /* boolean save */false,
    /* boolean print */false,
    /* boolean zoom */false,
    /* boolean tooltips */true);


    ChartFactory.setChartTheme(new StandardChartTheme("JFree/Shadow"));


    String machineName = "Dummy";
    JFreeChart chart = ChartFactory.createPieChart(machineName, // chart title
            createDataset(), // data
            true, // include legend
            true, false);


    this.setChart(chart);
    chart.setBackgroundPaint(Color.LIGHT_GRAY.brighter());              
    chart.setAntiAlias(true);

    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setBackgroundPaint(Color.GREEN);

    plot.setInteriorGap(0.04);
    plot.setOutlineVisible(false);

    // Color between the segments
    plot.setBaseSectionOutlinePaint(Color.BLACK);
    plot.setSectionOutlinesVisible(true);
    plot.setBaseSectionOutlineStroke(new BasicStroke(2.0f));

    plot.setLabelFont(new Font("Tahoma", Font.BOLD, 20));
    plot.setLabelLinkPaint(Color.WHITE);
    plot.setLabelLinkStroke(new BasicStroke(2.0f));
    plot.setLabelOutlineStroke(null);
    plot.setLabelPaint(Color.WHITE);
    plot.setLabelBackgroundPaint(null);

    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("({0}) {2}"));
    plot.setToolTipGenerator(new StandardPieToolTipGenerator("{0}: {2}"));

    plot.setNoDataMessage("No data available");
    plot.setIgnoreZeroValues(true);

}

private static PieDataset createDataset() {
    DefaultPieDataset dataset = new DefaultPieDataset();
    dataset.setValue("One", new Double(43.2));
    dataset.setValue("Two", new Double(10.0));
    dataset.setValue("Three", new Double(27.5));
    dataset.setValue("Four", new Double(17.5));
    dataset.setValue("Five", new Double(11.0));
    dataset.setValue("Six", new Double(19.4));
    return dataset;
}

When showing this chart I get the following result: enter image description here

As you can see the background is not green but black. If you look very closely to the bottom of the chart you can see a 1 pixel green line, so technically the background is drawn but overriten at some point later.

Now let's set the dataset to null, this gives the expected result, the background is green: enter image description here

What am I doing wrong, why is the background overwriteen with black if I have a valid dataset?

I've been trying for about two hours now and can't resolve it :/

SSCCEE:

The chart is part of a view inside an eclispe RCP where MyView is registered under the ID, which is also stored in the class MyView in the global final variable ID.

I create the view witht he following command:

PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(MyView.ID);

MyView:

package at.mypackage.views;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;

    import at.mypackage.charts.MyPieChart;


    public class MyView extends ViewPart {

        public static final String ID = "at.mypackage.views.MyView";

        @Override
        public void createPartControl(Composite parent) {
            parent.setLayoutData(new FillLayout(SWT.BORDER));
            MyPieChart chart = new MyPieChart(parent, SWT.BORDER);
        }

        @Override
        public void setFocus() {
            // TODO Auto-generated method stub

        }

}

MyPieChart:

package at.mypackage.charts;


import java.awt.Color;

import org.eclipse.swt.widgets.Composite;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PiePlot;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.general.PieDataset;
import org.jfree.experimental.chart.swt.ChartComposite;

public class MyPieChart extends ChartComposite {

    public MyPieChart(Composite parent, int style) {
        super(/* Composite comp */parent,
        /* int style */style,
        /* JFreeChart jfreechart */null,
        /* int width */10,
        /* int height */10,
        /* int minimumDrawW */1,
        /* int minimumDrawH */1,
        /* int maximumDrawW */Integer.MAX_VALUE,
        /* int maximumDrawH */Integer.MAX_VALUE,
        /* boolean usingBuffer */false,
        /* boolean properties */false,
        /* boolean save */false,
        /* boolean print */false,
        /* boolean zoom */false,
        /* boolean tooltips */true);

        JFreeChart chart = ChartFactory.createPieChart("Dummy", // chart title
                createDataset(), // data
                true, // include legend
                true, false);

        this.setChart(chart);
        chart.setBackgroundPaint(Color.LIGHT_GRAY.brighter());              

        PiePlot plot = (PiePlot) chart.getPlot();
        plot.setBackgroundPaint(Color.GREEN);       

    }

    private static PieDataset createDataset() {
        DefaultPieDataset dataset = new DefaultPieDataset();
        dataset.setValue("One", new Double(43.2));
        dataset.setValue("Two", new Double(10.0));
        dataset.setValue("Three", new Double(27.5));
        dataset.setValue("Four", new Double(17.5));
        dataset.setValue("Five", new Double(11.0));
        dataset.setValue("Six", new Double(19.4));
        return dataset;
    }



}
Was it helpful?

Solution

Disabling the shadow generator fixed the problem :)

plot.setShadowGenerator(null);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top