Exporting charts
In this tutorial, you will learn how to export charts. These instructions assume that you are familiar with the main features in CDE and the basic steps of creating a dashboard in CDE. In addition, these instructions assume that you have activated the CDE plugin.
Exporting charts with CGG
In this walk-through tutorial, you will export the bar chart with the Community Graphics Generator (CGG) using the demoDashboard CDE dashboard created in the Create a dashboard using RequireJS tutorial. To use CGG, open an existing CDE dashboard for editing, and select which charts in the dashboard you want to render as CGG charts.
Open the demoDashboard in CDE.
Log on to Pentaho User Console and navigate to the Browse Files perspective.
In the Folders pane, click to expand the
Public
folder, and then click to highlight thedemoDashboard
folder.demoDashboard example in the Browse Files perspective In the Files pane, click on demoDashboard and then, in theFile Actions pane, click Edit.
You are now in the Opened perspective with CDE in editing mode. The Editing:demoDashboard tab is now active in CDE.
In the Components perspective, press Shift G. In the Choose what charts to render as CGG popup, click to select the chartComponent check box.
This popup lists all the components available to CGG, such as the Community Charting Components (CCC) chart components. When you save the dashboard, CGG generates a JavaScript file for each chart selected in the popup and saves it in your solutions directory.
chartComponent option in the Choose what charts to render as CGG popup Click the Url button to generate a URL link to CGG which will export the target chart image. Copy the export link by selecting the full URL text and pressing CtrlC on your keyboard. When finished, click Close.
Url option in the Choose what charts to render as CGG popup Before we can use the export URL, we need to save the dashboard so the CGG scripts are generated and saved in the proper repository. To save the dashboard, on the CDE menu bar, click Save.
View the generated CGG JavaScript files. In Pentaho User Console, navigate to your
demoDashboard
folder. Note the following files:The
demoDashboard_chartComponent.js
contains the chart definitions.The
chartComponent.js
contains the same content as the above file. This file is saved for backwards compatibility with previous server versions.
Open a browser window and paste the export URL (from Step 3) into the browser's navigation bar. Press Enter. The chart image displays in the browser window.
Displayed chart image
By default, CGG exports images in the Portable Network Graphics format (PNG). If you want CGG to export the image in the Scalable Vector Graphics format (SVG), then change the outputType
in the URL query string to svg
as shown below.
http://localhost:8080/pentaho/plugin/cgg/api/services/draw?script=/public/demoDashboard/demoDashboard_chartComponent.js&outputType=svg
Exporting charts from a dashboard
In this walk-through tutorial, you will add an Export Chart button to export the bar chart from the demoDashboard CDE dashboard created in the Create a dashboard using RequireJS tutorial.
Open the demoDashboard in CDE.
(For detailed instructions, see Step 1 in Exporting Charts with CGG.)
Customize the layout for the export button.
In the Layout perspective, locate the mainContainerColumn column and add a row named
exportChartRow
.Select the exportChartRow and add a column named
exportChartObj
.Select the exportChartObj column and in the Properties pane, locate the Text Align property and set its value to Center.
Text Align property in Layout Structure perspective
Add and customize the export button.
In the Components perspective, in the left menu, expand the Others group and click on the Button Component.
Button Component in Components prespective In the Components pane, select the Button Component you just added. In the Properties pane, set the following values:
Property
Value
Name
exportChart
Label
Export Chart
HtmlObject
exportChartObj
4. Copy the following code to the **Expression** property:
```javascript
function f() {
this.dashboard
.getComponentByName('render_chartComponent')
.exportChart('png');
}
```
**Note:** This code allows you to retrieve the `chartComponent` component via the dashboard and execute its `exportChart` function by passing it the **png** parameter which defines the export file type as a PNG file.
When completed, the **Properties** pane should look similar to the image below.

5. In the Components perspective, press Shift G to display the Choose what charts to render as CGG popup. Make sure the chartComponent check box is selected, then click Close.

6. After saving the dashboard, return to Pentaho User Console, navigate to the Browse Files perspective and double-click the demoDashboard
file. The following chart displays:

7. Press the Export Chart button to download the chart file as a PNG file.

Last updated
Was this helpful?