Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.dbelectronics;
- import net.sf.jasperreports.engine.JRDataSource;
- import net.sf.jasperreports.engine.JRField;
- import net.sf.jasperreports.engine.JRException;
- /*
- This example is a custom JRDataSource containing 3 fields:
- - "Banda" wich contains 20 strings (used as labels in the chart)
- - "Calibracion" wich will be created dinamically from a CSV field (like "48,50,53,49")
- - "Verificacion" same as the previous one
- */
- public class BandasCSVDatasource implements JRDataSource {
- String[] labels = {"63","83","100","125","160","200","250","315","400","500","630","800",
- "1.0k","1.2k","1.6k","2.0k","2.5k","3.0k","4.0k","5.0k"};
- String[] calibracion;
- String[] verificacion;
- int index;
- public BandasCSVDatasource(String csv1, String csv2) {
- calibracion = csv1.split(",");
- verificacion = csv2.split(",");
- index = -1;
- }
- /* Optional method containing your field names */
- public static String[] fieldNames() {
- String[] fieldNames = {"Banda","Verificacion","Calibracion"};
- return fieldNames;
- }
- @Override
- public Object getFieldValue(JRField f) throws JRException {
- String fieldName = f.getName();
- Object o = null;
- if ( fieldName.equals("Banda") ) {
- o = labels[index];
- } else if ( fieldName.equals("Verificacion") ) {
- o = verificacion[index];
- } else {
- o = calibracion[index];
- }
- return o;
- }
- @Override
- public boolean next() throws JRException {
- index++;
- if (index>=20) {
- return false;
- } else {
- if (index<calibracion.length && index<verificacion.length) {
- return true;
- } else {
- return false;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement