use of org.jfree.chart.ChartRenderingInfo in project pentaho-platform by pentaho.
the class PieDatasetChartComponent method getXmlContent.
@Override
public Document getXmlContent() {
// Create a document that describes the result
Document result = DocumentHelper.createDocument();
IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext();
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
setXslProperty("baseUrl", requestContext.getContextPath());
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
setXslProperty("fullyQualifiedServerUrl", PentahoSystem.getApplicationContext().getFullyQualifiedServerURL());
// $NON-NLS-1$
String mapName = "chart" + AbstractChartComponent.chartCount++;
Document chartDefinition = jcrHelper.getSolutionDocument(definitionPath, RepositoryFilePermission.READ);
if (chartDefinition == null) {
// $NON-NLS-1$
Element errorElement = result.addElement("error");
errorElement.addElement("title").setText(// $NON-NLS-1$ //$NON-NLS-2$
Messages.getInstance().getString("ABSTRACTCHARTEXPRESSION.ERROR_0001_ERROR_GENERATING_CHART"));
// $NON-NLS-1$
String message = Messages.getInstance().getString("CHARTS.ERROR_0001_CHART_DEFINIION_MISSING", definitionPath);
// $NON-NLS-1$
errorElement.addElement("message").setText(message);
error(message);
return result;
}
// create a pie definition from the XML definition
dataDefinition = createChart(chartDefinition);
if (dataDefinition == null) {
// $NON-NLS-1$
Element errorElement = result.addElement("error");
errorElement.addElement("title").setText(// $NON-NLS-1$ //$NON-NLS-2$
Messages.getInstance().getString("ABSTRACTCHARTEXPRESSION.ERROR_0001_ERROR_GENERATING_CHART"));
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
String message = Messages.getInstance().getString("CHARTS.ERROR_0002_CHART_DATA_MISSING", actionPath);
// $NON-NLS-1$
errorElement.addElement("message").setText(message);
// System .out.println( result.asXML() );
return result;
}
// create an image for the dial using the JFreeChart engine
PrintWriter printWriter = new PrintWriter(new StringWriter());
// we'll dispay the title in HTML so that the dial image does not have
// to
// accommodate it
// $NON-NLS-1$
String chartTitle = "";
try {
if (height == -1) {
// $NON-NLS-1$
height = Integer.parseInt(chartDefinition.selectSingleNode("/chart/height").getText());
}
if (width == -1) {
// $NON-NLS-1$
width = Integer.parseInt(chartDefinition.selectSingleNode("/chart/width").getText());
}
} catch (Exception e) {
// go with the default
}
if (chartDefinition.selectSingleNode("/chart/urlTemplate") != null) {
// $NON-NLS-1$
// $NON-NLS-1$
urlTemplate = chartDefinition.selectSingleNode("/chart/urlTemplate").getText();
}
if (chartDefinition.selectSingleNode("/chart/paramName") != null) {
// $NON-NLS-1$
// $NON-NLS-1$
paramName = chartDefinition.selectSingleNode("/chart/paramName").getText();
}
// $NON-NLS-1$
Element root = result.addElement("charts");
DefaultPieDataset chartDataDefinition = (DefaultPieDataset) dataDefinition;
// if (chartDataDefinition.getRowCount() > 0) {
// create temporary file names
String[] tempFileInfo = createTempFile();
String fileName = tempFileInfo[AbstractChartComponent.FILENAME_INDEX];
String filePathWithoutExtension = tempFileInfo[AbstractChartComponent.FILENAME_WITHOUT_EXTENSION_INDEX];
ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
JFreeChartEngine.saveChart(chartDataDefinition, chartTitle, "", filePathWithoutExtension, width, height, JFreeChartEngine.OUTPUT_PNG, printWriter, info, // $NON-NLS-1$
this);
applyOuterURLTemplateParam();
populateInfo(info);
// $NON-NLS-1$
Element chartElement = root.addElement("chart");
// $NON-NLS-1$
chartElement.addElement("mapName").setText(mapName);
// $NON-NLS-1$
chartElement.addElement("width").setText(Integer.toString(width));
// $NON-NLS-1$
chartElement.addElement("height").setText(Integer.toString(height));
// for (int row = 0; row < chartDataDefinition.getRowCount(); row++) {
// for (int column = 0; column < chartDataDefinition.getColumnCount();
// column++) {
// Number value = chartDataDefinition.getValue(row, column);
// Comparable rowKey = chartDataDefinition.getRowKey(row);
// Comparable columnKey = chartDataDefinition.getColumnKey(column);
// Element valueElement = chartElement.addElement("value2D");
// //$NON-NLS-1$
// valueElement.addElement("value").setText(value.toString());
// //$NON-NLS-1$
// valueElement.addElement("row-key").setText(rowKey.toString());
// //$NON-NLS-1$
// valueElement.addElement("column-key").setText(columnKey.toString());
// //$NON-NLS-1$
// }
// }
String mapString = ImageMapUtilities.getImageMap(mapName, info);
// $NON-NLS-1$
chartElement.addElement("imageMap").setText(mapString);
// $NON-NLS-1$
chartElement.addElement("image").setText(fileName);
// }
return result;
}
use of org.jfree.chart.ChartRenderingInfo in project pentaho-platform by pentaho.
the class XYZSeriesCollectionChartComponent method getXmlContent.
@Override
public Document getXmlContent() {
// Create a document that describes the result
Document result = DocumentHelper.createDocument();
IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext();
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
setXslProperty("baseUrl", requestContext.getContextPath());
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
setXslProperty("fullyQualifiedServerUrl", PentahoSystem.getApplicationContext().getFullyQualifiedServerURL());
// $NON-NLS-1$
String mapName = "chart" + AbstractChartComponent.chartCount++;
Document chartDefinition = jcrHelper.getSolutionDocument(definitionPath, RepositoryFilePermission.READ);
if (chartDefinition == null) {
// $NON-NLS-1$
Element errorElement = result.addElement("error");
errorElement.addElement("title").setText(// $NON-NLS-1$ //$NON-NLS-2$
Messages.getInstance().getString("ABSTRACTCHARTEXPRESSION.ERROR_0001_ERROR_GENERATING_CHART"));
// $NON-NLS-1$
String message = Messages.getInstance().getString("CHARTS.ERROR_0001_CHART_DEFINIION_MISSING", definitionPath);
// $NON-NLS-1$
errorElement.addElement("message").setText(message);
error(message);
return result;
}
// create a pie definition from the XML definition
dataDefinition = createChart(chartDefinition);
if (dataDefinition == null) {
// $NON-NLS-1$
Element errorElement = result.addElement("error");
errorElement.addElement("title").setText(// $NON-NLS-1$ //$NON-NLS-2$
Messages.getInstance().getString("ABSTRACTCHARTEXPRESSION.ERROR_0001_ERROR_GENERATING_CHART"));
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
String message = Messages.getInstance().getString("CHARTS.ERROR_0002_CHART_DATA_MISSING", actionPath);
// $NON-NLS-1$
errorElement.addElement("message").setText(message);
// System .out.println( result.asXML() );
return result;
}
// create an image for the dial using the JFreeChart engine
PrintWriter printWriter = new PrintWriter(new StringWriter());
// we'll dispay the title in HTML so that the dial image does not have
// to
// accommodate it
// $NON-NLS-1$
String chartTitle = "";
try {
if (width == -1) {
// $NON-NLS-1$
width = Integer.parseInt(chartDefinition.selectSingleNode("/chart/width").getText());
}
if (height == -1) {
// $NON-NLS-1$
height = Integer.parseInt(chartDefinition.selectSingleNode("/chart/height").getText());
}
} catch (Exception e) {
// go with the default
}
if (chartDefinition.selectSingleNode("/chart/" + AbstractChartComponent.URLTEMPLATE_NODE_NAME) != null) {
// $NON-NLS-1$
urlTemplate = // $NON-NLS-1$
chartDefinition.selectSingleNode("/chart/" + AbstractChartComponent.URLTEMPLATE_NODE_NAME).getText();
}
if (chartDefinition.selectSingleNode("/chart/paramName") != null) {
// $NON-NLS-1$
// $NON-NLS-1$
paramName = chartDefinition.selectSingleNode("/chart/paramName").getText();
}
// $NON-NLS-1$
Element root = result.addElement("charts");
XYZSeriesCollectionChartDefinition chartDataDefinition = (XYZSeriesCollectionChartDefinition) dataDefinition;
if (chartDataDefinition.getSeriesCount() > 0) {
// create temporary file names
String[] tempFileInfo = createTempFile();
String fileName = tempFileInfo[AbstractChartComponent.FILENAME_INDEX];
String filePathWithoutExtension = tempFileInfo[AbstractChartComponent.FILENAME_WITHOUT_EXTENSION_INDEX];
ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
JFreeChartEngine.saveChart(chartDataDefinition, chartTitle, "", filePathWithoutExtension, width, height, JFreeChartEngine.OUTPUT_PNG, printWriter, info, // $NON-NLS-1$
this);
applyOuterURLTemplateParam();
populateInfo(info);
// $NON-NLS-1$
Element chartElement = root.addElement("chart");
// $NON-NLS-1$
chartElement.addElement("mapName").setText(mapName);
// $NON-NLS-1$
chartElement.addElement("width").setText(Integer.toString(width));
// $NON-NLS-1$
chartElement.addElement("height").setText(Integer.toString(height));
for (int row = 0; row < chartDataDefinition.getSeriesCount(); row++) {
for (int column = 0; column < chartDataDefinition.getItemCount(row); column++) {
Number value = chartDataDefinition.getY(row, column);
Comparable rowKey = chartDataDefinition.getSeriesKey(row);
Number columnKey = chartDataDefinition.getX(row, column);
// $NON-NLS-1$
Element valueElement = chartElement.addElement("value2D");
// $NON-NLS-1$
valueElement.addElement("value").setText(value.toString());
// $NON-NLS-1$
valueElement.addElement("row-key").setText(rowKey.toString());
// $NON-NLS-1$
valueElement.addElement("column-key").setText(columnKey.toString());
}
}
String mapString = ImageMapUtilities.getImageMap(mapName, info);
// $NON-NLS-1$
chartElement.addElement("imageMap").setText(mapString);
// $NON-NLS-1$
chartElement.addElement("image").setText(fileName);
}
return result;
}
use of org.jfree.chart.ChartRenderingInfo in project pentaho-platform by pentaho.
the class CategoryDatasetChartComponent method getXmlContent.
@Override
public Document getXmlContent() {
// Create a document that describes the result
Document result = DocumentHelper.createDocument();
IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext();
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
setXslProperty("baseUrl", requestContext.getContextPath());
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
setXslProperty("fullyQualifiedServerUrl", PentahoSystem.getApplicationContext().getFullyQualifiedServerURL());
// $NON-NLS-1$
String mapName = "chart" + AbstractChartComponent.chartCount++;
Document chartDefinition = jcrHelper.getSolutionDocument(definitionPath, RepositoryFilePermission.READ);
if (chartDefinition == null) {
// $NON-NLS-1$
Element errorElement = result.addElement("error");
errorElement.addElement("title").setText(// $NON-NLS-1$ //$NON-NLS-2$
Messages.getInstance().getString("ABSTRACTCHARTEXPRESSION.ERROR_0001_ERROR_GENERATING_CHART"));
// $NON-NLS-1$
String message = Messages.getInstance().getString("CHARTS.ERROR_0001_CHART_DEFINIION_MISSING", definitionPath);
// $NON-NLS-1$
errorElement.addElement("message").setText(message);
error(message);
return result;
}
// create a pie definition from the XML definition
dataDefinition = createChart(chartDefinition);
if (dataDefinition == null) {
// $NON-NLS-1$
Element errorElement = result.addElement("error");
errorElement.addElement("title").setText(// $NON-NLS-1$ //$NON-NLS-2$
Messages.getInstance().getString("ABSTRACTCHARTEXPRESSION.ERROR_0001_ERROR_GENERATING_CHART"));
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
String message = Messages.getInstance().getString("CHARTS.ERROR_0002_CHART_DATA_MISSING", actionPath);
// $NON-NLS-1$
errorElement.addElement("message").setText(message);
// System .out.println( result.asXML() );
return result;
}
// create an image for the dial using the JFreeChart engine
PrintWriter printWriter = new PrintWriter(new StringWriter());
// we'll dispay the title in HTML so that the dial image does not have
// to
// accommodate it
// $NON-NLS-1$
String chartTitle = "";
try {
if (width == -1) {
// $NON-NLS-1$
width = Integer.parseInt(chartDefinition.selectSingleNode("/chart/width").getText());
}
} catch (NumberFormatException ignored) {
// go with the default
}
try {
if (height == -1) {
// $NON-NLS-1$
height = Integer.parseInt(chartDefinition.selectSingleNode("/chart/height").getText());
}
} catch (NumberFormatException ignored) {
// go with the default
}
if (chartDefinition.selectSingleNode("/chart/" + AbstractChartComponent.URLTEMPLATE_NODE_NAME) != null) {
// $NON-NLS-1$
urlTemplate = // $NON-NLS-1$
chartDefinition.selectSingleNode("/chart/" + AbstractChartComponent.URLTEMPLATE_NODE_NAME).getText();
}
if (chartDefinition.selectSingleNode("/chart/paramName") != null) {
// $NON-NLS-1$
// $NON-NLS-1$
paramName = chartDefinition.selectSingleNode("/chart/paramName").getText();
}
// $NON-NLS-1$
Element root = result.addElement("charts");
DefaultCategoryDataset chartDataDefinition = (DefaultCategoryDataset) dataDefinition;
if (chartDataDefinition.getRowCount() > 0) {
// create temporary file names
String[] tempFileInfo = createTempFile();
String fileName = tempFileInfo[AbstractChartComponent.FILENAME_INDEX];
String filePathWithoutExtension = tempFileInfo[AbstractChartComponent.FILENAME_WITHOUT_EXTENSION_INDEX];
ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
JFreeChartEngine.saveChart(chartDataDefinition, chartTitle, "", filePathWithoutExtension, width, height, JFreeChartEngine.OUTPUT_PNG, printWriter, info, // $NON-NLS-1$
this);
applyOuterURLTemplateParam();
populateInfo(info);
// $NON-NLS-1$
Element chartElement = root.addElement("chart");
// $NON-NLS-1$
chartElement.addElement("mapName").setText(mapName);
// $NON-NLS-1$
chartElement.addElement("width").setText(Integer.toString(width));
// $NON-NLS-1$
chartElement.addElement("height").setText(Integer.toString(height));
for (int row = 0; row < chartDataDefinition.getRowCount(); row++) {
for (int column = 0; column < chartDataDefinition.getColumnCount(); column++) {
Number value = chartDataDefinition.getValue(row, column);
Comparable rowKey = chartDataDefinition.getRowKey(row);
Comparable columnKey = chartDataDefinition.getColumnKey(column);
// $NON-NLS-1$
Element valueElement = chartElement.addElement("value2D");
// $NON-NLS-1$
valueElement.addElement("value").setText(value.toString());
// $NON-NLS-1$
valueElement.addElement("row-key").setText(rowKey.toString());
// $NON-NLS-1$
valueElement.addElement("column-key").setText(columnKey.toString());
}
}
String mapString = ImageMapUtilities.getImageMap(mapName, info);
// $NON-NLS-1$
chartElement.addElement("imageMap").setText(mapString);
// $NON-NLS-1$
chartElement.addElement("image").setText(fileName);
}
return result;
}
use of org.jfree.chart.ChartRenderingInfo in project SIMVA-SoS by SESoS.
the class ChartCanvas method draw.
/**
* Draws the content of the canvas and updates the
* {@code renderingInfo} attribute with the latest rendering
* information.
*/
public final void draw() {
GraphicsContext ctx = getGraphicsContext2D();
ctx.save();
double width = getWidth();
double height = getHeight();
if (width > 0 && height > 0) {
ctx.clearRect(0, 0, width, height);
this.info = new ChartRenderingInfo();
this.chart.draw(this.g2, new Rectangle((int) width, (int) height), this.anchor, this.info);
}
ctx.restore();
this.anchor = null;
}
use of org.jfree.chart.ChartRenderingInfo in project SIMVA-SoS by SESoS.
the class BoxAndWhiskerRendererTest method testDrawWithNullQ1.
/**
* Draws a chart where the dataset contains a null Q1 value.
*/
@Test
public void testDrawWithNullQ1() {
boolean success;
try {
DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();
dataset.add(new BoxAndWhiskerItem(new Double(1.0), new Double(2.0), null, new Double(4.0), new Double(0.5), new Double(4.5), new Double(-0.5), new Double(5.5), null), "S1", "C1");
CategoryPlot plot = new CategoryPlot(dataset, new CategoryAxis("Category"), new NumberAxis("Value"), new BoxAndWhiskerRenderer());
ChartRenderingInfo info = new ChartRenderingInfo();
JFreeChart chart = new JFreeChart(plot);
/* BufferedImage image = */
chart.createBufferedImage(300, 200, info);
success = true;
} catch (Exception e) {
success = false;
}
assertTrue(success);
}
Aggregations