use of org.xwiki.chart.ChartCustomizer in project xwiki-platform by xwiki.
the class DefaultChartGenerator method generate.
@Override
public byte[] generate(ChartModel model, Map<String, String> parameters) throws ChartGeneratorException {
setDefaultParams(parameters);
String type = parameters.get(TYPE_PARAM);
String title = parameters.get(TITLE_PARAM);
PlotGenerator generator;
try {
generator = contextComponentManager.get().getInstance(PlotGenerator.class, type);
} catch (ComponentLookupException e) {
throw new ChartGeneratorException(String.format("No such chart type : [%s].", type), e);
}
Plot plot = generator.generate(model, parameters);
JFreeChart jfchart = new JFreeChart(title, plot);
// Run customizations
for (ChartCustomizer customizer : this.customizerProvider.get()) {
customizer.customize(jfchart, parameters);
}
int width = Integer.parseInt(parameters.get(WIDTH_PARAM));
int height = Integer.parseInt(parameters.get(HEIGHT_PARAM));
try {
return ChartUtilities.encodeAsPNG(jfchart.createBufferedImage(width, height));
} catch (IOException ex) {
throw new ChartGeneratorException("Error while png encoding the chart image.");
}
}
Aggregations