Search in sources :

Example 1 with JDBCCategoryDataset

use of org.jfree.data.jdbc.JDBCCategoryDataset in project opennms by OpenNMS.

the class ChartUtils method buildCategoryDataSet.

/**
     * @param chartConfig
     * @param baseDataSet
     * @throws SQLException
     */
private static DefaultCategoryDataset buildCategoryDataSet(BarChart chartConfig) throws SQLException {
    DefaultCategoryDataset baseDataSet = new DefaultCategoryDataset();
    /*
         * Configuration can contain more than one series.  This loop adds
         * single series data sets returned from sql query to a base data set
         * to be displayed in a the chart. 
         */
    Connection conn = null;
    try {
        conn = DataSourceFactory.getInstance().getConnection();
        Iterator<SeriesDef> it = chartConfig.getSeriesDefCollection().iterator();
        while (it.hasNext()) {
            SeriesDef def = it.next();
            JDBCCategoryDataset dataSet = new JDBCCategoryDataset(conn, def.getJdbcDataSet().getSql());
            for (int i = 0; i < dataSet.getRowCount(); i++) {
                for (int j = 0; j < dataSet.getColumnCount(); j++) {
                    baseDataSet.addValue(dataSet.getValue(i, j), def.getSeriesName(), dataSet.getColumnKey(j));
                }
            }
        }
    } finally {
        if (conn != null) {
            conn.close();
        }
    }
    return baseDataSet;
}
Also used : SeriesDef(org.opennms.netmgt.config.charts.SeriesDef) Connection(java.sql.Connection) JDBCCategoryDataset(org.jfree.data.jdbc.JDBCCategoryDataset) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) Paint(java.awt.Paint)

Aggregations

Paint (java.awt.Paint)1 Connection (java.sql.Connection)1 DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)1 JDBCCategoryDataset (org.jfree.data.jdbc.JDBCCategoryDataset)1 SeriesDef (org.opennms.netmgt.config.charts.SeriesDef)1