IChartLinkGenerator chartLinkGenerator =
contentLinkingTemplate == null ? null : new ChartLinkGenerator( contentLinkingTemplate );
IChartDataModel chartDataModel =
ChartBeanFactory.createChartDataModel( data, scalingFactor, convertNullsToZero, valueColumn, seriesColumn,
categoryColumn, chartModel );
IOutput output = ChartBeanFactory.createChart( chartModel, chartDataModel, chartLinkGenerator );
// Wrap output as necessary
if ( OpenFlashChartPlugin.PLUGIN_ID.equals( chartEngine ) ) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
output.persistChart( outputStream, getOutputType(), chartWidth, chartHeight );
String persistedChart = new String( outputStream.toByteArray(), "utf-8" ); //$NON-NLS-1$
IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext();
String flashContent =
ChartBeansGeneratorUtil.mergeOpenFlashChartHtmlTemplate( persistedChart.replaceAll( "\"", "\\\\\"" ),
//$NON-NLS-1$ //$NON-NLS-2$
requestContext.getContextPath() + this.getSwfPath() + "/" + getSwfName() ); //$NON-NLS-1$
is = new ByteArrayInputStream( flashContent.getBytes( "utf-8" ) ); //$NON-NLS-1$
} else if ( JFreeChartPlugin.PLUGIN_ID.equals( chartEngine ) ) {
if ( "html".equals( outputType ) || ( chartLinkGenerator != null ) ) { //$NON-NLS-1$
File imageFile =
PentahoSystem.getApplicationContext().createTempFile( PentahoSessionHolder.getSession(),
"tmp_chart_", ".png", false ); //$NON-NLS-1$
FileOutputStream outputStream = new FileOutputStream( imageFile );
output.persistChart( outputStream, OutputTypes.FILE_TYPE_PNG, chartWidth, chartHeight );
String imageMapName = null;
String imageMap = null;
if ( chartLinkGenerator != null ) {
imageMapName = imageFile.getName().substring( 0, imageFile.getName().indexOf( '.' ) );
imageMap = ( (JFreeChartOutput) output ).getMap( imageMapName );
}
String jFreeChartHtml =
ChartBeansGeneratorUtil.mergeJFreeChartHtmlTemplate( imageFile, imageMap, imageMapName, chartWidth,
chartHeight, PentahoRequestContextHolder.getRequestContext().getContextPath() );
is = new ByteArrayInputStream( jFreeChartHtml.getBytes( "utf-8" ) ); //$NON-NLS-1$
} else {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
output.persistChart( outputStream, getOutputType(), chartWidth, chartHeight );
is = new ByteArrayInputStream( outputStream.toByteArray() );
}
}
int val = 0;