9.2. Specifying the Data Source for Chart Viewer

Using parameters, you can specify a data source for the Chart Viewer in order to display different data with a chart template or create a chart from scratch.

9.2.1. Data Read From a Database

This is some sample JSP/JNLP code that uses the Chart Viewer to view a chart drawn using data extracted from a database.

<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0+" href="EspressViewer.jnlp">
<information>
<title>Espress Viewer</title>
<vendor>Quadbase Systems Inc.</vendor>
<offline-allowed/>
</information>
<resources>
<j2se version="1.8+" max-heap-size="1024m"/>
<jar href="lib/EspressViewer.jar"/>
</resources>
<security>
<all-permissions/>
</security>
<applet-desc
name="Chart Viewer"
main-class="quadbase.chartviewer.Viewer"
width="640"
height="480">

<PARAM name="sourceDB" value="jdbc:odbc:DataSource, sun.jdbc.odbc.JdbcOdbcDriver, username, password, select * from products">
<param name="dataMap" value="0 1 -1 3">
<param name="chartType" value="3D Column">

</applet-desc>
<update check="always" policy="always"/>
</jnlp>

The arguments of dataMap specify how the chart utilizes different columns from the input data to plot the chart. In case of a scatter chart, they are series, x-value, y-value, and z-value. For a high low open close or high low chart the numbers are series, category, high, low, open, and close. For all other charts, the arguments are series, category, sumBy, and value. If you would like more information,please see the chapter on Column Mapping in the Chart API reference. The argument chartType specifies the type of chart to be displayed and it can be one of:

  • 2D Column

  • 3D Column

  • 2D bar

  • 3D bar

  • 2D stack bar

  • 3D stack bar

  • 2D stack column

  • 3D stack column

  • 2D area

  • 3D area

  • 2D stack area

  • 3D stack area

  • 2D line

  • 3D line

  • 2D pie

  • 3D pie

  • 2D scatter

  • 3D scatter

  • 2D High Low

  • 3D High Low

  • 2D HLCO

  • 3D HLCO

  • 2D 100% Column

  • 3D 100% Column

  • 3D Surface

  • 2D Bubble

  • 2D Overlay

  • 2D Box

  • 2D Radar

  • 2D Dial

  • 2D Gantt

  • 2D Polar

9.2.2. Data Read From a Data File

This HTML/jsp code draws a chart using data from a data file:

<applet-desc code = "quadbase.chartviewer.Viewer.class" width=640 height=480>

      <param name="sourceFile" value="http://.../test.dat">
      <param name="dataMap" value="-1 0 -1 1">
      <param name="chartType" value="3D Pie"> 
</applet-desc>

9.2.3. Data Read From an Argument

It is possible to have Chart Viewer read in data directly from the HTML/jsp file itself rather than from a data file or from a database.

<applet-desc code = "quadbase.chartviewer.Viewer.class" width=640 height=480>

      <param name="sourceData" value="int, string, int | value, name, vol | 10, 'John', 20 | 3, 'Mary', 30 | 8, 'Kevin', 3 | 9, 'James', 22">
      <param name="dataMap" value="-1 1 -1 2">
      <param name="chartType" value="3D Bar">

</applet-desc> 

The format for the parameter sourceData is the same as the data file format, except that each line is ended by a vertical bar “|”.