Example usage for org.jfree.chart.plot Plot setNoDataMessage

List of usage examples for org.jfree.chart.plot Plot setNoDataMessage

Introduction

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

Prototype

public void setNoDataMessage(String message) 

Source Link

Document

Sets the message that is displayed when the dataset is empty or null, and sends a PlotChangeEvent to all registered listeners.

Usage

From source file:net.nosleep.superanalyzer.util.Misc.java

public static void formatChart(Plot plot) {
    plot.setBackgroundPaint(Color.white);
    plot.setOutlineVisible(false);/*from  www  .jav a2 s .  co m*/
    plot.setNoDataMessage(Misc.getString("NO_DATA_TO_DISPLAY"));

    if ((plot instanceof XYPlot)) {
        XYPlot xyPlot = (XYPlot) plot;
        xyPlot.setDomainGridlinePaint(Color.gray);
        xyPlot.setRangeGridlinePaint(Color.gray);
    }
}

From source file:org.pentaho.plugin.jfreereport.reportcharts.MultiPieChartExpression.java

protected void configureSubChart(final JFreeChart chart) {
    final TextTitle chartTitle = chart.getTitle();
    if (chartTitle != null) {
        if (getPieTitleFont() != null) {
            chartTitle.setFont(getPieTitleFont());
        } else {//w ww .  j a  v  a2s  . c  o m
            final Font titleFont = Font.decode(getTitleFont());
            chartTitle.setFont(titleFont);
        }
    }

    if (isAntiAlias() == false) {
        chart.setAntiAlias(false);
    }

    final LegendTitle chLegend = chart.getLegend();
    if (chLegend != null) {
        final RectangleEdge loc = translateEdge(getLegendLocation().toLowerCase());
        if (loc != null) {
            chLegend.setPosition(loc);
        }
        if (getLegendFont() != null) {
            chLegend.setItemFont(Font.decode(getLegendFont()));
        }
        if (!isDrawLegendBorder()) {
            chLegend.setBorder(BlockBorder.NONE);
        }
        if (getLegendBackgroundColor() != null) {
            chLegend.setBackgroundPaint(getLegendBackgroundColor());
        }
        if (getLegendTextColor() != null) {
            chLegend.setItemPaint(getLegendTextColor());
        }
    }

    final Plot plot = chart.getPlot();
    plot.setNoDataMessageFont(Font.decode(getLabelFont()));

    final String pieNoData = getPieNoDataMessage();
    if (pieNoData != null) {
        plot.setNoDataMessage(pieNoData);
    } else {
        final String message = getNoDataMessage();
        if (message != null) {
            plot.setNoDataMessage(message);
        }
    }
}

From source file:org.pentaho.platform.uifoundation.chart.JFreeChartEngine.java

private static void updatePlot(final Plot plot, final ChartDefinition chartDefinition) {
    plot.setBackgroundPaint(chartDefinition.getPlotBackgroundPaint());
    plot.setBackgroundImage(chartDefinition.getPlotBackgroundImage());

    plot.setNoDataMessage(chartDefinition.getNoDataMessage());

    // create a custom palette if it was defined
    if (chartDefinition.getPaintSequence() != null) {
        DefaultDrawingSupplier drawingSupplier = new DefaultDrawingSupplier(chartDefinition.getPaintSequence(),
                DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE,
                DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,
                DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE,
                DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE);
        plot.setDrawingSupplier(drawingSupplier);
    }//from  w  ww . j a va2  s  . co m
    plot.setOutlineStroke(null); // TODO define outline stroke

    if (plot instanceof CategoryPlot) {
        CategoryPlot categoryPlot = (CategoryPlot) plot;
        CategoryDatasetChartDefinition categoryDatasetChartDefintion = (CategoryDatasetChartDefinition) chartDefinition;
        categoryPlot.setOrientation(categoryDatasetChartDefintion.getOrientation());
        CategoryAxis domainAxis = categoryPlot.getDomainAxis();
        if (domainAxis != null) {
            domainAxis.setLabel(categoryDatasetChartDefintion.getDomainTitle());
            domainAxis.setLabelFont(categoryDatasetChartDefintion.getDomainTitleFont());
            if (categoryDatasetChartDefintion.getDomainTickFont() != null) {
                domainAxis.setTickLabelFont(categoryDatasetChartDefintion.getDomainTickFont());
            }
            domainAxis.setCategoryLabelPositions(categoryDatasetChartDefintion.getCategoryLabelPositions());
        }
        NumberAxis numberAxis = (NumberAxis) categoryPlot.getRangeAxis();
        if (numberAxis != null) {
            numberAxis.setLabel(categoryDatasetChartDefintion.getRangeTitle());
            numberAxis.setLabelFont(categoryDatasetChartDefintion.getRangeTitleFont());
            if (categoryDatasetChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                numberAxis.setLowerBound(categoryDatasetChartDefintion.getRangeMinimum());
            }
            if (categoryDatasetChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                numberAxis.setUpperBound(categoryDatasetChartDefintion.getRangeMaximum());
            }

            if (categoryDatasetChartDefintion.getRangeTickFormat() != null) {
                numberAxis.setNumberFormatOverride(categoryDatasetChartDefintion.getRangeTickFormat());
            }
            if (categoryDatasetChartDefintion.getRangeTickFont() != null) {
                numberAxis.setTickLabelFont(categoryDatasetChartDefintion.getRangeTickFont());
            }
            if (categoryDatasetChartDefintion.getRangeTickUnits() != null) {
                numberAxis.setTickUnit(new NumberTickUnit(categoryDatasetChartDefintion.getRangeTickUnits()));
            }
        }

    }
    if (plot instanceof PiePlot) {
        PiePlot pie = (PiePlot) plot;
        PieDatasetChartDefinition pieDefinition = (PieDatasetChartDefinition) chartDefinition;
        pie.setInteriorGap(pieDefinition.getInteriorGap());
        pie.setStartAngle(pieDefinition.getStartAngle());
        pie.setLabelFont(pieDefinition.getLabelFont());
        if (pieDefinition.getLabelPaint() != null) {
            pie.setLabelPaint(pieDefinition.getLabelPaint());
        }
        pie.setLabelBackgroundPaint(pieDefinition.getLabelBackgroundPaint());
        if (pieDefinition.isLegendIncluded()) {
            StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator("{0}"); //$NON-NLS-1$
            pie.setLegendLabelGenerator(labelGen);
        }
        if (pieDefinition.getExplodedSlices() != null) {
            for (Iterator iter = pieDefinition.getExplodedSlices().iterator(); iter.hasNext();) {
                pie.setExplodePercent((Comparable) iter.next(), .30);
            }
        }
        pie.setLabelGap(pieDefinition.getLabelGap());
        if (!pieDefinition.isDisplayLabels()) {
            pie.setLabelGenerator(null);
        } else {
            if (pieDefinition.isLegendIncluded()) {
                StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator("{1} ({2})"); //$NON-NLS-1$
                pie.setLabelGenerator(labelGen);
            } else {
                StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator(
                        "{0} = {1} ({2})"); //$NON-NLS-1$
                pie.setLabelGenerator(labelGen);
            }
        }
    }
    if (plot instanceof MultiplePiePlot) {
        MultiplePiePlot pies = (MultiplePiePlot) plot;
        CategoryDatasetChartDefinition categoryDatasetChartDefintion = (CategoryDatasetChartDefinition) chartDefinition;
        pies.setDataset(categoryDatasetChartDefintion);
    }
    if (plot instanceof MeterPlot) {
        MeterPlot meter = (MeterPlot) plot;
        DialWidgetDefinition widget = (DialWidgetDefinition) chartDefinition;
        List intervals = widget.getIntervals();
        Iterator intervalIterator = intervals.iterator();
        while (intervalIterator.hasNext()) {
            MeterInterval interval = (MeterInterval) intervalIterator.next();
            meter.addInterval(interval);
        }

        meter.setNeedlePaint(widget.getNeedlePaint());
        meter.setDialShape(widget.getDialShape());
        meter.setDialBackgroundPaint(widget.getPlotBackgroundPaint());
        meter.setRange(new Range(widget.getMinimum(), widget.getMaximum()));

    }
    if (plot instanceof XYPlot) {
        XYPlot xyPlot = (XYPlot) plot;
        if (chartDefinition instanceof XYSeriesCollectionChartDefinition) {
            XYSeriesCollectionChartDefinition xySeriesCollectionChartDefintion = (XYSeriesCollectionChartDefinition) chartDefinition;
            xyPlot.setOrientation(xySeriesCollectionChartDefintion.getOrientation());
            ValueAxis domainAxis = xyPlot.getDomainAxis();
            if (domainAxis != null) {
                domainAxis.setLabel(xySeriesCollectionChartDefintion.getDomainTitle());
                domainAxis.setLabelFont(xySeriesCollectionChartDefintion.getDomainTitleFont());
                domainAxis.setVerticalTickLabels(xySeriesCollectionChartDefintion.isDomainVerticalTickLabels());
                if (xySeriesCollectionChartDefintion.getDomainTickFormat() != null) {
                    ((NumberAxis) domainAxis)
                            .setNumberFormatOverride(xySeriesCollectionChartDefintion.getDomainTickFormat());
                }
                if (xySeriesCollectionChartDefintion.getDomainTickFont() != null) {
                    domainAxis.setTickLabelFont(xySeriesCollectionChartDefintion.getDomainTickFont());
                }
                if (xySeriesCollectionChartDefintion.getDomainMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                    domainAxis.setLowerBound(xySeriesCollectionChartDefintion.getDomainMinimum());
                }
                if (xySeriesCollectionChartDefintion.getDomainMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                    domainAxis.setUpperBound(xySeriesCollectionChartDefintion.getDomainMaximum());
                }
            }

            ValueAxis rangeAxis = xyPlot.getRangeAxis();
            if (rangeAxis != null) {
                rangeAxis.setLabel(xySeriesCollectionChartDefintion.getRangeTitle());
                rangeAxis.setLabelFont(xySeriesCollectionChartDefintion.getRangeTitleFont());
                if (xySeriesCollectionChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                    rangeAxis.setLowerBound(xySeriesCollectionChartDefintion.getRangeMinimum());
                }
                if (xySeriesCollectionChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                    rangeAxis.setUpperBound(xySeriesCollectionChartDefintion.getRangeMaximum());
                }
                if (xySeriesCollectionChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                    rangeAxis.setLowerBound(xySeriesCollectionChartDefintion.getRangeMinimum());
                }
                if (xySeriesCollectionChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                    rangeAxis.setUpperBound(xySeriesCollectionChartDefintion.getRangeMaximum());
                }
                if (xySeriesCollectionChartDefintion.getRangeTickFormat() != null) {
                    ((NumberAxis) rangeAxis)
                            .setNumberFormatOverride(xySeriesCollectionChartDefintion.getRangeTickFormat());
                }
                if (xySeriesCollectionChartDefintion.getRangeTickFont() != null) {
                    rangeAxis.setTickLabelFont(xySeriesCollectionChartDefintion.getRangeTickFont());
                }
            }

        } else if (chartDefinition instanceof TimeSeriesCollectionChartDefinition) {
            TimeSeriesCollectionChartDefinition timeSeriesCollectionChartDefintion = (TimeSeriesCollectionChartDefinition) chartDefinition;
            xyPlot.setOrientation(timeSeriesCollectionChartDefintion.getOrientation());
            ValueAxis domainAxis = xyPlot.getDomainAxis();
            if (domainAxis != null) {
                domainAxis.setLabel(timeSeriesCollectionChartDefintion.getDomainTitle());
                domainAxis.setLabelFont(timeSeriesCollectionChartDefintion.getDomainTitleFont());
                domainAxis
                        .setVerticalTickLabels(timeSeriesCollectionChartDefintion.isDomainVerticalTickLabels());
                if (domainAxis instanceof DateAxis) {
                    DateAxis da = (DateAxis) domainAxis;
                    if (timeSeriesCollectionChartDefintion.getDateMinimum() != null) {
                        da.setMinimumDate(timeSeriesCollectionChartDefintion.getDateMinimum());
                    }
                    if (timeSeriesCollectionChartDefintion.getDateMaximum() != null) {
                        da.setMaximumDate(timeSeriesCollectionChartDefintion.getDateMaximum());
                    }
                }
            }

            ValueAxis rangeAxis = xyPlot.getRangeAxis();
            if (rangeAxis != null) {
                rangeAxis.setLabel(timeSeriesCollectionChartDefintion.getRangeTitle());
                rangeAxis.setLabelFont(timeSeriesCollectionChartDefintion.getRangeTitleFont());
                if (timeSeriesCollectionChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                    rangeAxis.setLowerBound(timeSeriesCollectionChartDefintion.getRangeMinimum());
                }
                if (timeSeriesCollectionChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                    rangeAxis.setUpperBound(timeSeriesCollectionChartDefintion.getRangeMaximum());
                }
            }
        } else if (chartDefinition instanceof XYZSeriesCollectionChartDefinition) {
            XYZSeriesCollectionChartDefinition xyzSeriesCollectionChartDefintion = (XYZSeriesCollectionChartDefinition) chartDefinition;
            xyPlot.setOrientation(xyzSeriesCollectionChartDefintion.getOrientation());
            ValueAxis domainAxis = xyPlot.getDomainAxis();
            if (domainAxis != null) {
                domainAxis.setLabel(xyzSeriesCollectionChartDefintion.getDomainTitle());
                domainAxis.setLabelFont(xyzSeriesCollectionChartDefintion.getDomainTitleFont());
                domainAxis
                        .setVerticalTickLabels(xyzSeriesCollectionChartDefintion.isDomainVerticalTickLabels());
                if (xyzSeriesCollectionChartDefintion.getDomainMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                    domainAxis.setLowerBound(xyzSeriesCollectionChartDefintion.getDomainMinimum());
                }
                if (xyzSeriesCollectionChartDefintion.getDomainMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                    domainAxis.setUpperBound(xyzSeriesCollectionChartDefintion.getDomainMaximum());
                }
                if (xyzSeriesCollectionChartDefintion.getDomainTickFormat() != null) {
                    ((NumberAxis) domainAxis)
                            .setNumberFormatOverride(xyzSeriesCollectionChartDefintion.getDomainTickFormat());
                }
                if (xyzSeriesCollectionChartDefintion.getDomainTickFont() != null) {
                    domainAxis.setTickLabelFont(xyzSeriesCollectionChartDefintion.getDomainTickFont());
                }
            }

            ValueAxis rangeAxis = xyPlot.getRangeAxis();
            if (rangeAxis != null) {
                rangeAxis.setLabel(xyzSeriesCollectionChartDefintion.getRangeTitle());
                rangeAxis.setLabelFont(xyzSeriesCollectionChartDefintion.getRangeTitleFont());
                rangeAxis.setLowerBound(xyzSeriesCollectionChartDefintion.getRangeMinimum());
                if (xyzSeriesCollectionChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                    rangeAxis.setLowerBound(xyzSeriesCollectionChartDefintion.getRangeMinimum());
                }
                if (xyzSeriesCollectionChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                    rangeAxis.setUpperBound(xyzSeriesCollectionChartDefintion.getRangeMaximum());
                }
                if (xyzSeriesCollectionChartDefintion.getRangeTickFormat() != null) {
                    ((NumberAxis) rangeAxis)
                            .setNumberFormatOverride(xyzSeriesCollectionChartDefintion.getRangeTickFormat());
                }
                if (xyzSeriesCollectionChartDefintion.getRangeTickFont() != null) {
                    rangeAxis.setTickLabelFont(xyzSeriesCollectionChartDefintion.getRangeTickFont());
                }
            }

        }
    }
}

From source file:org.pentaho.plugin.jfreereport.reportcharts.AbstractChartExpression.java

protected void configureChart(final JFreeChart chart) {
    // Misc Properties
    final TextTitle chartTitle = chart.getTitle();
    if (chartTitle != null) {
        final Font titleFont = Font.decode(getTitleFont());
        chartTitle.setFont(titleFont);/* www .j  a  va  2  s.c  om*/
    }

    if (isAntiAlias() == false) {
        chart.setAntiAlias(false);
    }

    chart.setBorderVisible(isShowBorder());

    final Color backgroundColor = parseColorFromString(getBackgroundColor());
    if (backgroundColor != null) {
        chart.setBackgroundPaint(backgroundColor);
    }

    if (plotBackgroundColor != null) {
        chart.getPlot().setBackgroundPaint(plotBackgroundColor);
    }
    chart.getPlot().setBackgroundAlpha(plotBackgroundAlpha);
    chart.getPlot().setForegroundAlpha(plotForegroundAlpha);
    final Color borderCol = parseColorFromString(getBorderColor());
    if (borderCol != null) {
        chart.setBorderPaint(borderCol);
    }

    //remove legend if showLegend = false
    if (!isShowLegend()) {
        chart.removeLegend();
    } else { //if true format legend
        final LegendTitle chLegend = chart.getLegend();
        if (chLegend != null) {
            final RectangleEdge loc = translateEdge(legendLocation.toLowerCase());
            if (loc != null) {
                chLegend.setPosition(loc);
            }
            if (getLegendFont() != null) {
                chLegend.setItemFont(Font.decode(getLegendFont()));
            }
            if (!isDrawLegendBorder()) {
                chLegend.setBorder(BlockBorder.NONE);
            }
            if (legendBackgroundColor != null) {
                chLegend.setBackgroundPaint(legendBackgroundColor);
            }
            if (legendTextColor != null) {
                chLegend.setItemPaint(legendTextColor);
            }
        }

    }

    final Plot plot = chart.getPlot();
    plot.setNoDataMessageFont(Font.decode(getLabelFont()));

    final String message = getNoDataMessage();
    if (message != null) {
        plot.setNoDataMessage(message);
    }

    plot.setOutlineVisible(isChartSectionOutline());

    if (backgroundImage != null) {
        if (plotImageCache != null) {
            plot.setBackgroundImage(plotImageCache);
        } else {
            final ExpressionRuntime expressionRuntime = getRuntime();
            final ProcessingContext context = expressionRuntime.getProcessingContext();
            final ResourceKey contentBase = context.getContentBase();
            final ResourceManager manager = context.getResourceManager();
            try {
                final ResourceKey key = createKeyFromString(manager, contentBase, backgroundImage);
                final Resource resource = manager.create(key, null, Image.class);
                final Image image = (Image) resource.getResource();
                plot.setBackgroundImage(image);
                plotImageCache = image;
            } catch (Exception e) {
                logger.error("ABSTRACTCHARTEXPRESSION.ERROR_0007_ERROR_RETRIEVING_PLOT_IMAGE", e); //$NON-NLS-1$
                throw new IllegalStateException("Failed to process chart");
            }
        }
    }
}

From source file:org.openfaces.component.chart.impl.helpers.JFreeChartAdapter.java

public JFreeChartAdapter(Plot plot, Chart chart) {
    super(null, JFreeChart.DEFAULT_TITLE_FONT, plot, false);

    final boolean chartBackgroundPaintDefined = chart.getChartView().getBackgroundPaint() != null;
    if (chart.isLegendVisible()) {
        addSubtitle(new LegendAdapter(plot, chart));
    }//from w  w w .  ja  v a 2  s. c o m

    if (chart.getTitle() != null) {
        setTitle(new TextTitleAdapter(chart));
    }

    if (chartBackgroundPaintDefined) {
        setBackgroundPaint(chart.getChartView().getBackgroundPaint());
    }

    //TODO: separate style properties

    StyleObjectModel cssChartModel = chart.getStyleObjectModel();
    if (cssChartModel != null) {
        if (!chartBackgroundPaintDefined) {
            setBackgroundPaint(cssChartModel.getBackground());
        }

        StyleBorderModel border = cssChartModel.getBorder();
        if (border != null && !border.isNone()) {
            setBorderPaint(border.getColor());
            setBorderVisible(true);
        } else {
            setBorderVisible(false);
        }
    }

    Float foregroundAlpha = chart.getChartView().getForegroundAlpha();
    if (foregroundAlpha != null) {
        plot.setForegroundAlpha(foregroundAlpha);
    }

    ChartNoDataMessage chartNoDataMessage = chart.getNoDataMessage();
    if (chartNoDataMessage != null && chartNoDataMessage.getText() != null) {
        plot.setNoDataMessage(chartNoDataMessage.getText());

        StyleObjectModel cssMessageModel = chartNoDataMessage.getStyleObjectModel();
        if (cssMessageModel != null) {
            plot.setNoDataMessagePaint(cssMessageModel.getColor());
            plot.setNoDataMessageFont(CSSUtil.getFont(cssMessageModel));
        }
    }
}