Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Here we add the 21 series to the plot which in turn gets added to the chart.

Code Block
java
java
titlecreateChartModel: Dummy Chart Structure
  private static ChartModel createChartModel() {

    List<Series> seriesList = new ArrayList<Series>();
    Series series1 = new Series();
    series1.setForegroundColor(0x2D00FF);
    seriesList.add(series1);
    Series series2 = new Series();
    series2.setForegroundColor(0x11FFE4);
    seriesList.add(series2);

    // lines omitted

    Series series21 = new Series();
    series21.setForegroundColor(0x0596FF);
    seriesList.add(series21);

    CategoricalBarPlot plot = new CategoricalBarPlot();
    plot.setSeries(seriesList);
    plot.setOrientation(Orientation.HORIZONTAL);

    ChartModel chartModel = new ChartModel();
    chartModel.setTitle("Bar Chart Using Pentaho ChartBeans");
    chartModel.setPlot(plot);
    return chartModel;
  }

...

For now, styling is included in the Chart Structure chart structure when using the Java ChartModel API.

Generating Charts

Now let's pull all of the pieces together. First we have a main method that "boots" Pentaho ChartBeans. This reads various configuration files and otherwise readies the system for chart processing requests. Next we render one chart using the JFreeChart plugin for Pentaho ChartBeans and then we render another chart using the Open Flash Chart plugin for Pentaho ChartBeans. Note that both use the same ChartModel and ChartTableModel.

...

Example from an End User Perspective

Chart Data

In this example, we're just going to query against a database using an MQL query. See Generating Charts in this section.

Chart Structure

The ChartBeans XML document for this example is below. Its relatively brief because our data and styling is separate from the chart structure. The elements in this document define a stylesheet reference, a chart title, the series, and the chart orientation.

...

Code Block
none
none
titletheme.css
.series1 {
  color: #2D00FF;
  -x-pentaho-chart-line-width: 2px;
}

.series2 {
  color: #11FFE4;
  -x-pentaho-chart-line-width: 2px;
}

/* lines omitted */

.series18 {
  color: #B7FFE5;
  -x-pentaho-chart-line-width: 2px;
}

Generating Charts

Note: The ChartComponent mentioned below is not complete! It is a work in progress and cannot be used as is. This example is for illustration only.

Code Block
xml
xml
titlePentaho Action Sequence (for use in the Pentaho BI Platform)

<?xml version="1.0" encoding="UTF-8"?>
<action-sequence> 
  <name>chartbeans_demo.xaction</name>
  <title>chartbeans_demo.xaction</title>
  <version>1</version>
  <logging-level>debug</logging-level>
  <documentation>
    <description>Generate a chart through ChartBeans from an MQL statement.</description>  
    <help>Pass in an MQL statement that returns a table of three columns. The first column is the series, the second is the category and the third is the data.</help>
    <result-type>rule</result-type>  
  </documentation>

  <inputs>
    <query type="string"> 
      <sources> 
        <request>query</request> 
      </sources>  
    </query> 
    <chart-model type="string">
      <sources>
        <request>chart-model</request>
      </sources>
    </chart-model>
    <chart-width type="integer">
      <sources>
        <request>chart-width</request>
      </sources>
      <default-value>-1</default-value> 
    </chart-width>
    <chart-height type="integer">
      <sources>
        <request>chart-height</request>
      </sources>
      <default-value>-1</default-value>
    </chart-height>
    <series-column type="string">
      <sources>
        <request>series-column</request>
      </sources>
      <default-value/> 
    </series-column>
    <category-column type="string">
      <sources>
        <request>category-column</request>
      </sources>
      <default-value/> 
    </category-column>
    <value-column type="string">
      <sources>
        <request>value-column</request>
      </sources>
      <default-value/>
    </value-column>
  </inputs>

  <outputs>
    <outputstream type="content"> 
      <destinations> 
        <response>content</response> 
      </destinations> 
    </outputstream> 
  </outputs>

  <resources/>

  <actions> 
  
    <action-definition>
      <action-inputs>
        <query />
      </action-inputs>
      <action-outputs>
        <rule-result type="result-set" mapping="chartdata"/>
      </action-outputs>
      <component-name>MQLRelationalDataComponent</component-name>
      <action-type>rule</action-type>
      <component-definition>
        <live>true</live>
        <display-names>false</display-names>
      </component-definition>
    </action-definition>

    <action-definition>
      <component-name>org.pentaho.platform.engine.services.solution.PojoComponent</component-name>
      <action-inputs> 
        <chart-model type="string"/>
        <chartdata type="result-set" />
        <chart-width type="integer"/>
        <chart-height type="integer"/>
        <series-column type="string"/>
        <category-column type="string"/>
        <value-column type="string"/>
      </action-inputs>
      <action-outputs>
        <outputstream/>
      </action-outputs>
      <component-definition> 
        <class>org.pentaho.platform.plugin.action.chartbeans.ChartComponent</class> 
      </component-definition>
      <action-name>Test the test POJO</action-name>  
      <logging-level>DEBUG</logging-level> 
    </action-definition>
    
  </actions> 
</action-sequence>

Results

Here is the result using the JFreeChart plugin for Pentaho ChartBeans:

...