Example usage for org.jfree.chart.plot PiePlot PiePlot

List of usage examples for org.jfree.chart.plot PiePlot PiePlot

Introduction

In this page you can find the example usage for org.jfree.chart.plot PiePlot PiePlot.

Prototype

public PiePlot() 

Source Link

Document

Creates a new plot.

Usage

From source file:org.sonar.server.charts.deprecated.PieChart.java

public PieChart(Map<String, String> params) {
    super(params);
    jfreechart = new JFreeChart(null, TextTitle.DEFAULT_FONT, new PiePlot(), false);
}

From source file:org.jfree.chart.demo.XYBlockChartDemo3.java

private static JFreeChart createChart(XYZDataset xyzdataset) {
    NumberAxis numberaxis = new NumberAxis("X");
    numberaxis.setLowerMargin(0.0D);//from   w  w w .  java2s . c  o m
    numberaxis.setUpperMargin(0.0D);
    NumberAxis numberaxis1 = new NumberAxis("Y");
    numberaxis1.setAutoRangeIncludesZero(false);
    numberaxis1.setInverted(true);
    numberaxis1.setLowerMargin(0.0D);
    numberaxis1.setUpperMargin(0.0D);
    numberaxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    XYBlockRenderer xyblockrenderer = new XYBlockRenderer();
    LookupPaintScale lookuppaintscale = new LookupPaintScale(0.5D, 3.5D, Color.black);
    lookuppaintscale.add(0.5D, Color.green);
    lookuppaintscale.add(1.5D, Color.orange);
    lookuppaintscale.add(2.5D, Color.red);
    xyblockrenderer.setPaintScale(lookuppaintscale);
    XYPlot xyplot = new XYPlot(xyzdataset, numberaxis, numberaxis1, xyblockrenderer);
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    xyplot.setForegroundAlpha(0.66F);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    JFreeChart jfreechart = new JFreeChart("XYBlockChartDemo3", xyplot);
    jfreechart.removeLegend();
    jfreechart.setBackgroundPaint(Color.white);
    SymbolAxis symbolaxis = new SymbolAxis(null, new String[] { "", "OK", "Uncertain", "Bad" });
    symbolaxis.setRange(0.5D, 3.5D);
    symbolaxis.setPlot(new PiePlot());
    symbolaxis.setGridBandsVisible(false);
    PaintScaleLegend paintscalelegend = new PaintScaleLegend(lookuppaintscale, symbolaxis);
    paintscalelegend.setAxisOffset(5D);
    paintscalelegend.setPosition(RectangleEdge.BOTTOM);
    paintscalelegend.setMargin(new RectangleInsets(5D, 5D, 5D, 5D));
    jfreechart.addSubtitle(paintscalelegend);
    return jfreechart;
}

From source file:org.jfree.chart.demo.XYBlockChartDemo2.java

private static JFreeChart createChart(XYZDataset xyzdataset) {
    DateAxis dateaxis = new DateAxis("Date");
    dateaxis.setLowerMargin(0.0D);//from  ww w .j  a  v a  2  s. c om
    dateaxis.setUpperMargin(0.0D);
    dateaxis.setInverted(true);
    NumberAxis numberaxis = new NumberAxis("Hour");
    numberaxis.setUpperMargin(0.0D);
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    XYBlockRenderer xyblockrenderer = new XYBlockRenderer();
    xyblockrenderer.setBlockWidth(86400000D);
    xyblockrenderer.setBlockAnchor(RectangleAnchor.BOTTOM_LEFT);
    LookupPaintScale lookuppaintscale = new LookupPaintScale(0.5D, 4.5D, Color.white);
    lookuppaintscale.add(0.5D, Color.red);
    lookuppaintscale.add(1.5D, Color.green);
    lookuppaintscale.add(2.5D, Color.blue);
    lookuppaintscale.add(3.5D, Color.yellow);
    xyblockrenderer.setPaintScale(lookuppaintscale);
    XYPlot xyplot = new XYPlot(xyzdataset, dateaxis, numberaxis, xyblockrenderer);
    xyplot.setOrientation(PlotOrientation.HORIZONTAL);
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setRangeGridlinePaint(Color.white);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    JFreeChart jfreechart = new JFreeChart("XYBlockChartDemo2", xyplot);
    jfreechart.removeLegend();
    jfreechart.setBackgroundPaint(Color.white);
    SymbolAxis symbolaxis = new SymbolAxis(null,
            new String[] { "", "Unavailable", "Free", "Group 1", "Group 2" });
    symbolaxis.setRange(0.5D, 4.5D);
    symbolaxis.setPlot(new PiePlot());
    symbolaxis.setGridBandsVisible(false);
    PaintScaleLegend paintscalelegend = new PaintScaleLegend(lookuppaintscale, symbolaxis);
    paintscalelegend.setMargin(new RectangleInsets(3D, 10D, 3D, 10D));
    paintscalelegend.setPosition(RectangleEdge.BOTTOM);
    paintscalelegend.setAxisOffset(5D);
    jfreechart.addSubtitle(paintscalelegend);
    return jfreechart;
}

From source file:it.eng.spagobi.engines.chart.bo.charttypes.XYCharts.BlockChart.java

/**
 * Creates a chart for the specified dataset.
 * /*w w w  . j a va2s.c o m*/
 * @param dataset  the dataset.
 * 
 * @return A chart instance.
 */
public JFreeChart createChart(DatasetMap datasets) {
    XYZDataset dataset = (XYZDataset) datasets.getDatasets().get("1");
    //Creates the xAxis with its label and style
    NumberAxis xAxis = new NumberAxis(xLabel);
    xAxis.setLowerMargin(0.0);
    xAxis.setUpperMargin(0.0);
    xAxis.setLabel(xLabel);
    if (addLabelsStyle != null && addLabelsStyle.getFont() != null) {
        xAxis.setLabelFont(addLabelsStyle.getFont());
        xAxis.setLabelPaint(addLabelsStyle.getColor());
    }
    //Creates the yAxis with its label and style
    NumberAxis yAxis = new NumberAxis(yLabel);

    yAxis.setAutoRangeIncludesZero(false);
    yAxis.setInverted(false);
    yAxis.setLowerMargin(0.0);
    yAxis.setUpperMargin(0.0);
    yAxis.setTickLabelsVisible(true);
    yAxis.setLabel(yLabel);
    if (addLabelsStyle != null && addLabelsStyle.getFont() != null) {
        yAxis.setLabelFont(addLabelsStyle.getFont());
        yAxis.setLabelPaint(addLabelsStyle.getColor());
    }
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    Color outboundCol = new Color(Integer.decode(outboundColor).intValue());

    //Sets the graph paint scale and the legend paintscale
    LookupPaintScale paintScale = new LookupPaintScale(zvalues[0], (new Double(zrangeMax)).doubleValue(),
            outboundCol);
    LookupPaintScale legendPaintScale = new LookupPaintScale(0.5, 0.5 + zvalues.length, outboundCol);

    for (int ke = 0; ke <= (zvalues.length - 1); ke++) {
        Double key = (new Double(zvalues[ke]));
        Color temp = (Color) colorRangeMap.get(key);
        paintScale.add(zvalues[ke], temp);
        legendPaintScale.add(0.5 + ke, temp);
    }
    //Configures the renderer
    XYBlockRenderer renderer = new XYBlockRenderer();
    renderer.setPaintScale(paintScale);
    double blockHeight = (new Double(blockH)).doubleValue();
    double blockWidth = (new Double(blockW)).doubleValue();
    renderer.setBlockWidth(blockWidth);
    renderer.setBlockHeight(blockHeight);

    //configures the plot with title, subtitle, axis ecc.
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.black);
    plot.setRangeGridlinePaint(Color.black);
    plot.setDomainCrosshairPaint(Color.black);

    plot.setForegroundAlpha(0.66f);
    plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5));
    JFreeChart chart = new JFreeChart(plot);
    TextTitle title = setStyleTitle(name, styleTitle);
    chart.setTitle(title);
    if (subName != null && !subName.equals("")) {
        TextTitle subTitle = setStyleTitle(subName, styleSubTitle);
        chart.addSubtitle(subTitle);
    }
    chart.removeLegend();
    chart.setBackgroundPaint(Color.white);

    //Sets legend labels
    SymbolAxis scaleAxis = new SymbolAxis(null, legendLabels);
    scaleAxis.setRange(0.5, 0.5 + zvalues.length);
    scaleAxis.setPlot(new PiePlot());
    scaleAxis.setGridBandsVisible(false);
    scaleAxis.setLabel(zLabel);
    //scaleAxis.setLabelAngle(3.14/2);
    scaleAxis.setLabelFont(addLabelsStyle.getFont());
    scaleAxis.setLabelPaint(addLabelsStyle.getColor());

    //draws legend as chart subtitle
    PaintScaleLegend psl = new PaintScaleLegend(legendPaintScale, scaleAxis);
    psl.setAxisOffset(2.0);
    psl.setPosition(RectangleEdge.RIGHT);
    psl.setMargin(new RectangleInsets(5, 1, 5, 1));
    chart.addSubtitle(psl);

    if (yLabels != null) {
        //Sets y legend labels
        LookupPaintScale legendPaintScale2 = new LookupPaintScale(0, (yLabels.length - 1), Color.white);

        for (int ke = 0; ke < yLabels.length; ke++) {
            Color temp = Color.white;
            legendPaintScale2.add(1 + ke, temp);
        }

        SymbolAxis scaleAxis2 = new SymbolAxis(null, yLabels);
        scaleAxis2.setRange(0, (yLabels.length - 1));
        scaleAxis2.setPlot(new PiePlot());
        scaleAxis2.setGridBandsVisible(false);

        //draws legend as chart subtitle
        PaintScaleLegend psl2 = new PaintScaleLegend(legendPaintScale2, scaleAxis2);
        psl2.setAxisOffset(5.0);
        psl2.setPosition(RectangleEdge.LEFT);
        psl2.setMargin(new RectangleInsets(8, 1, 40, 1));
        psl2.setStripWidth(0);
        psl2.setStripOutlineVisible(false);
        chart.addSubtitle(psl2);
    }

    return chart;
}

From source file:it.eng.spagobi.engines.chart.bo.charttypes.blockcharts.TimeBlockChart.java

@Override
public JFreeChart createChart(DatasetMap datasets) {
    logger.debug("IN");
    super.createChart(datasets);
    DefaultXYZDataset dataset = (DefaultXYZDataset) datasets.getDatasets().get("1");

    DateAxis xAxis = new DateAxis(yLabel);
    xAxis.setLowerMargin(0.0);//  w w  w. ja  va 2s .  c om
    xAxis.setUpperMargin(0.0);
    xAxis.setInverted(false);
    xAxis.setDateFormatOverride(new SimpleDateFormat("dd/MM/yyyy"));
    if (dateAutoRange) {
        xAxis.setAutoRange(true);
    } else {
        DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
        DateTickUnit unit = new DateTickUnit(DateTickUnit.DAY, 1, formatter);
        xAxis.setTickUnit(unit);
    }

    if (dateMin != null && dateMax != null) {
        xAxis.setRange(dateMin, addDay(dateMax));
    } else {
        xAxis.setRange(minDateFound, addDay(maxDateFound));
    }

    //      Calendar c=new GregorianCalendar();
    //      c.set(9 + 2000, Calendar.JANUARY, 1);
    //      java.util.Date minima=c.getTime();
    //      Calendar c1=new GregorianCalendar();
    //      c1.set(9 + 2000, Calendar.FEBRUARY, 1);
    //      java.util.Date massima=c1.getTime();

    NumberAxis yAxis = new NumberAxis(xLabel);
    yAxis.setUpperMargin(0.0);
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    yAxis.setRange(hourMin, hourMax);

    XYBlockRenderer renderer = new XYBlockRenderer();
    renderer.setBlockWidth(BLOCK_HEIGHT);
    // one block for each minute!
    renderer.setBlockHeight(0.017);
    //renderer.setBlockWidth(1);
    renderer.setBlockAnchor(RectangleAnchor.BOTTOM_LEFT);

    //      MyXYItemLabelGenerator my=new MyXYItemLabelGenerator();
    //      renderer.setItemLabelsVisible(null);
    //      renderer.setSeriesItemLabelGenerator(0, my);
    //      renderer.setSeriesItemLabelsVisible(0, true);

    //      XYTextAnnotation annotation1 = new XYTextAnnotation(
    //      "P_",1.2309372E12, 14.3);
    //      XYTextAnnotation annotation2 = new XYTextAnnotation(
    //      "P_",1.2308508E12, 16.3);

    for (Iterator iterator = annotations.keySet().iterator(); iterator.hasNext();) {
        String annotationCode = (String) iterator.next();
        AnnotationBlock annotationBlock = annotations.get(annotationCode);
        XYTextAnnotation xyAnnotation = new XYTextAnnotation(annotationBlock.getAnnotation(),
                annotationBlock.getXPosition() + ANNOTATION_HEIGHT, annotationBlock.getYPosition());
        if (styleAnnotation != null) {
            xyAnnotation.setFont(new Font(styleAnnotation.getFontName(), Font.BOLD, styleAnnotation.getSize()));
            xyAnnotation.setPaint(styleAnnotation.getColor());
        } else {
            xyAnnotation.setFont(new Font("Nome", Font.BOLD, 8));
            xyAnnotation.setPaint(Color.BLACK);
        }

        xyAnnotation.setTextAnchor(TextAnchor.BOTTOM_LEFT);
        renderer.addAnnotation(xyAnnotation);
    }

    logger.debug("Annotation set");

    LookupPaintScale paintScale = new LookupPaintScale(0.5, ranges.size() + 0.5, color);
    String[] labels = new String[ranges.size() + 1];
    labels[0] = "";

    // ******************** SCALE ****************************
    for (Iterator iterator = ranges.iterator(); iterator.hasNext();) {
        RangeBlocks range = (RangeBlocks) iterator.next();
        Integer index = patternRangeIndex.get(range.getPattern());
        Color color = range.getColor();
        if (color != null) {
            //Paint colorTransparent=new Color(color.getRed(), color.getGreen(), color.getBlue(), 50);         
            Paint colorTransparent = null;
            if (addTransparency == true) {
                colorTransparent = new Color(color.getRed(), color.getGreen(), color.getBlue(), 50);
            } else {
                colorTransparent = new Color(color.getRed(), color.getGreen(), color.getBlue());
            }
            paintScale.add(index + 0.5, colorTransparent);
        }
        //String insertLabel="            "+range.getLabel();
        String insertLabel = range.getLabel();
        labels[index + 1] = insertLabel;
    }
    renderer.setPaintScale(paintScale);

    SymbolAxis scaleAxis = new SymbolAxis(null, labels);
    scaleAxis.setRange(0.5, ranges.size() + 0.5);
    scaleAxis.setPlot(new PiePlot());
    scaleAxis.setGridBandsVisible(false);

    org.jfree.chart.title.PaintScaleLegend psl = new PaintScaleLegend(paintScale, scaleAxis);
    psl.setMargin(new RectangleInsets(3, 10, 3, 10));
    psl.setPosition(RectangleEdge.BOTTOM);
    psl.setAxisOffset(5.0);
    // ******************** END SCALE ****************************

    logger.debug("Scale Painted");

    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setOrientation(PlotOrientation.HORIZONTAL);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5));

    logger.debug("Plot set");

    JFreeChart chart = new JFreeChart(name, plot);
    if (styleTitle != null) {
        TextTitle title = setStyleTitle(name, styleTitle);
        chart.setTitle(title);
    }
    chart.removeLegend();
    chart.setBackgroundPaint(Color.white);
    chart.addSubtitle(psl);

    logger.debug("OUT");

    return chart;

}

From source file:SciTK.PlotXYZBlock.java

private void init(String x_label, String y_label, String window_title) {
    chart = ChartFactory.createScatterPlot("", x_label, y_label, data, PlotOrientation.VERTICAL, false, true,
            false);/*from  w  ww.j  a va2  s. co m*/

    // turn off borders of the plot:
    XYPlot p = chart.getXYPlot();
    p.getDomainAxis().setLowerMargin(0.0);
    p.getDomainAxis().setUpperMargin(0.0);
    p.getRangeAxis().setLowerMargin(0.0);
    p.getRangeAxis().setUpperMargin(0.0);

    // --------------------------------------------
    //          set up a lookup table
    // --------------------------------------------
    // this is how we render the block plots:
    XYBlockRenderer renderer = new XYBlockRenderer();
    // need to find max and min z of the data set:
    double min = 0;
    double max = 0;
    for (int i = 0; i < data.getSeriesCount(); i++) // iterate over data sets
    {
        for (int j = 0; j < data.getItemCount(i); j++) // iterate over points in dataset
        {
            if (data.getZValue(i, j) < min)
                min = data.getZValue(i, j);
            else if (data.getZValue(i, j) > max)
                max = data.getZValue(i, j);
        }
    }
    // create paint scale using min and max values, default color black:
    LookupPaintScale paintScale = new LookupPaintScale(min, max, Color.black);
    // set up the LUT:
    double step_size = (max - min) / 255.; // step size for LUT
    for (int i = 0; i < 256; i++) {
        paintScale.add(min + i * step_size, new Color(i, i, i, 255));
    }
    renderer.setPaintScale(paintScale);
    // set this renderer to the plot:
    p.setRenderer(renderer);

    // --------------------------------------------
    //          set up a color bar
    // --------------------------------------------
    // create an array of display labels:
    num_labels = 10; // default to 10 labels on color bar
    double display_step_size = (max - min) / ((double) num_labels);
    String[] scale_bar_labels = new String[num_labels + 1];
    // to format numbers in scientific notation:
    DecimalFormat formater = new DecimalFormat("0.#E0");
    // create list of labesl:
    for (int i = 0; i <= num_labels; i++) {
        scale_bar_labels[i] = formater.format(min + i * display_step_size);
    }
    // create axis:
    SymbolAxis scaleAxis = new SymbolAxis(null, scale_bar_labels);
    scaleAxis.setRange(min, max);
    scaleAxis.setPlot(new PiePlot());
    scaleAxis.setGridBandsVisible(false);
    // set up the paint scale:
    psl = new PaintScaleLegend(paintScale, scaleAxis);
    psl.setBackgroundPaint(new Color(255, 255, 255, 0)); // clear background
    // set up frame with buffer region to allow text display
    psl.setFrame(new LineBorder((Paint) Color.BLACK, new BasicStroke((float) 1.0),
            new RectangleInsets(15, 10, 15, 10)));
    psl.setAxisOffset(5.0);
    // display on right side:
    psl.setPosition(RectangleEdge.RIGHT);
    // margin around color scale:
    psl.setMargin(new RectangleInsets(20, 15, 20, 15));
    // add to the chart so it will be displayed by default:
    chart.addSubtitle(psl);

    // --------------------------------------------
    //          WINDOW-RELATED UI
    // --------------------------------------------
    // set up the generic plot UI:
    super.window_title = window_title;
    super.initUI();

    // add another menu item
    JMenuBar mb = super.getJMenuBar(); // get the menu bar
    // find menu named "Plot"
    JMenu menu_plot = null;
    for (int i = 0; i < mb.getMenuCount(); i++) {
        if (mb.getMenu(i).getText() == "Plot")
            menu_plot = mb.getMenu(i);
    }
    // Add a new checkbox for the color scale bar
    JCheckBoxMenuItem menu_plot_scalebar = new JCheckBoxMenuItem("Color Scale");
    menu_plot_scalebar.setToolTipText("Show color scale bar?");
    menu_plot_scalebar.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            AbstractButton aButton = (AbstractButton) event.getSource();
            boolean selected = aButton.getModel().isSelected();
            setScaleBar(selected);
        }
    });
    // set appropirate checkbox state:
    menu_plot_scalebar.setState(true);
    if (menu_plot != null) // sanity check
        menu_plot.add(menu_plot_scalebar);

}