Search in sources :

Example 1 with PlotGeneratorException

use of org.xwiki.chart.PlotGeneratorException in project xwiki-platform by xwiki.

the class AbstractXYPlotGenerator method generate.

@Override
public Plot generate(ChartModel model, Map<String, String> parameters) throws PlotGeneratorException {
    XYDataset dataset;
    ValueAxis domainAxis;
    ValueAxis rangeAxis;
    if (model.getDataset() instanceof XYDataset) {
        dataset = (XYDataset) model.getDataset();
    } else {
        throw new PlotGeneratorException("Incompatible dataset for xy plot.");
    }
    if (model.getAxis(0) instanceof ValueAxis) {
        domainAxis = (ValueAxis) model.getAxis(0);
    } else {
        throw new PlotGeneratorException("Incompatible axis 0 for xy plot.");
    }
    if (model.getAxis(1) instanceof ValueAxis) {
        rangeAxis = (ValueAxis) model.getAxis(1);
    } else {
        throw new PlotGeneratorException("Incompatible axis 1 for xy plot.");
    }
    return new XYPlot(dataset, domainAxis, rangeAxis, getRenderer(parameters));
}
Also used : XYPlot(org.jfree.chart.plot.XYPlot) ValueAxis(org.jfree.chart.axis.ValueAxis) XYDataset(org.jfree.data.xy.XYDataset) PlotGeneratorException(org.xwiki.chart.PlotGeneratorException)

Example 2 with PlotGeneratorException

use of org.xwiki.chart.PlotGeneratorException in project xwiki-platform by xwiki.

the class PiePlotGenerator method generate.

@Override
public Plot generate(ChartModel model, Map<String, String> parameters) throws PlotGeneratorException {
    PieDataset dataset;
    try {
        dataset = (PieDataset) model.getDataset();
    } catch (ClassCastException e) {
        throw new PlotGeneratorException("Incompatible dataset for the pie plot.");
    }
    PiePlot piePlot = new PiePlot(dataset);
    // Allow customizing the label to use
    String pieLabelFormat = parameters.get(PIE_LABEL_FORMAT_KEY);
    if (pieLabelFormat != null) {
        piePlot.setLabelGenerator(new StandardPieSectionLabelGenerator(pieLabelFormat, NumberFormat.getNumberInstance(), NumberFormat.getPercentInstance()));
    }
    return piePlot;
}
Also used : PieDataset(org.jfree.data.general.PieDataset) PiePlot(org.jfree.chart.plot.PiePlot) StandardPieSectionLabelGenerator(org.jfree.chart.labels.StandardPieSectionLabelGenerator) PlotGeneratorException(org.xwiki.chart.PlotGeneratorException)

Example 3 with PlotGeneratorException

use of org.xwiki.chart.PlotGeneratorException in project xwiki-platform by xwiki.

the class AbstractCategoryPlotGenerator method generate.

@Override
public Plot generate(ChartModel model, Map<String, String> parameters) throws PlotGeneratorException {
    CategoryDataset dataset;
    CategoryAxis domainAxis;
    ValueAxis rangeAxis;
    if (model.getDataset() instanceof CategoryDataset) {
        dataset = (CategoryDataset) model.getDataset();
    } else {
        throw new PlotGeneratorException("Incompatible dataset for category plot.");
    }
    if (model.getAxis(0) instanceof CategoryAxis) {
        domainAxis = (CategoryAxis) model.getAxis(0);
    } else {
        throw new PlotGeneratorException("Incompatible axis 0 for category plot.");
    }
    if (model.getAxis(1) instanceof ValueAxis) {
        rangeAxis = (ValueAxis) model.getAxis(1);
    } else {
        throw new PlotGeneratorException("Incompatible axis 1 for category plot.");
    }
    return new CategoryPlot(dataset, domainAxis, rangeAxis, getRenderer(parameters));
}
Also used : CategoryAxis(org.jfree.chart.axis.CategoryAxis) CategoryDataset(org.jfree.data.category.CategoryDataset) ValueAxis(org.jfree.chart.axis.ValueAxis) CategoryPlot(org.jfree.chart.plot.CategoryPlot) PlotGeneratorException(org.xwiki.chart.PlotGeneratorException)

Aggregations

PlotGeneratorException (org.xwiki.chart.PlotGeneratorException)3 ValueAxis (org.jfree.chart.axis.ValueAxis)2 CategoryAxis (org.jfree.chart.axis.CategoryAxis)1 StandardPieSectionLabelGenerator (org.jfree.chart.labels.StandardPieSectionLabelGenerator)1 CategoryPlot (org.jfree.chart.plot.CategoryPlot)1 PiePlot (org.jfree.chart.plot.PiePlot)1 XYPlot (org.jfree.chart.plot.XYPlot)1 CategoryDataset (org.jfree.data.category.CategoryDataset)1 PieDataset (org.jfree.data.general.PieDataset)1 XYDataset (org.jfree.data.xy.XYDataset)1