danimaniarqsoft
1/20/2015 - 4:17 AM

1.0Readme.md

#Open Source INFO

DSL Framework for JFreeChart

Introduction

The present project try to make the Chart generation easy through a Fluent Api [1]. The core of the Api is based on JFreechart.

@Chart Annotation

The engine of the DSL for create Charts use the @Chart annotation for create the whole Chart. Basically, you have to decorate the class on your class with the Annotation and add properties that will map on graph properties.

Let's to build a graph of "amount vs age " with the next information:

PlayerMountAgeDate
Cristiano Ronaldo1344.5672927/09/2014
Messi2344.5672727/09/2014
Bale544.5672527/09/2014

The steps for create a graph are shown next:

Steps:

  1. Create a JavaBean Class. and add an @Graph Annotation on top Of the class.
  2. Configure the The DSL for create the Graph

###Create a JavaBean Class###

The Pojo created is shown next:


@Chart(chartType = ChartType.PIE_CHART, xProperty = "edad", yProperty = "cantidad")
public class Persona {

    private String persona;
    
    private double cantidad;

    private int edad;

    private Date fecha;
    
   //Getters and Setters methods
     .
     .

###Configure the The DSL for create the Graph.###

Here I show a snipped of code for create a graph Based on the DSL and @Graph annotation:

import static com.danimaniarqsoft.report.poi.dsl.WorkbookBuilder.createWorkbook;
    private List<Persona> personasDataset;
     //Fill personasDataset from some datasource
    JFreeChart chart = createChart().ofTypeXYPlotChart()
                        .withXAxisLabel("X-edad").
                        withYAxisLabel("Y-cantidad")
                        .withChartTitle("Reflection")
                        .addDataSet(personasDataset, Persona.class).
                        createChart();
                    
    ChartUtilities.saveChartAsJPEG(new File("ReflectionChart.jpg"),

@Graph Annotation####

The @Graph annotation has a lot of properties for control the way how the DSL have to build the graph. The next table describe each property:

Aligments

PropertyDescriptionDefault
nameThe name of the columnnothing, it is mandatory
chartTypeThis property is used for choose the kind of Graph we would like to build. The value is defined in the Enum com.danimaniarqsoft.report.chart.dsl.ChartTypenothing, it is mandatory
xPropertyIn this property we have to provide the correct name of the instance class that we want to use for print a point into the graph, This property represent the x coordinate of the point that will be printed in the graphnothing, it is mandatory

© danimaniArqsoft


  1. Fluent Interface, Martin Fowler on December twenty of 2005 write about a certain style of interface which he decided to name fluent interface. We write DSL's based on the concept of Fluent Interface

DSL Framework for Apache Poi

Introduction

The present project try to make the Excel development easy through Fluent Api for create Excel documents. The core Api for the DSL [1] is based on Apache POI.

Excel Column Annotation

The engine of the DSL for create Excel documents use the @ExcelColumn annotation to create the whole Document. Basically, you have to decorate the attributes on your class with the Annotation and add properties that will map on the cell.

Let's to build a excel document like it show next:

PersonaCantidadEdadFecha
Cristiano Ronaldo1344.5672927/09/2014
Messi2344.5672727/09/2014
Bale544.5672527/09/2014

The steps for create a document are shown next:

Steps:

  1. Create a JavaBean Class. and add an @ExcelAnnotation on each property of the class property where we want to map in the excel document.
  2. Configure the The DSL for create the Document.

###Create a JavaBean Class###

The Pojo created is shown next:

public class Persona {

    @ExcelColumn(name = "Persona")
    private String persona;

    @ExcelColumn(name = "Cantidad")
    private double cantidad;

    @ExcelColumn(name = "Edad")
    private int edad;

    @ExcelColumn(name = "Fecha")
    private Date fecha;
    
   //Getters and Setters methods
     .
     .

###Configure the The DSL for create the Document.###

Here I show a snipped of code for create a document Based on the DSL and @ExcelColumn annotation:

import static com.danimaniarqsoft.report.poi.dsl.WorkbookBuilder.createWorkbook;
Workbook wb = createWorkbook(WorkbookEnum.XLSX)
              .createSheet("hoja1")
              .createHeader(Persona.class)
              .createRows(personas, Persona.class)
              .buildWorkbook();

@ExcelAnnotation####

The @ExcelAnnotation has a lot of properties for control the way that the DSL have to build the Excel Document. The next table describe each property:

Aligments

PropertyDescriptionDefault
nameThe name of the columnnothing, it is mandatory
dateFormatThis property is used for java.util.Date type. The value is a String with the date format defined on Java Date Format"dd/MM/YYYY"
textPositionthis property is used for align vertical text both Horizontally and vertically on a CellTextPosition.ALIGN_CENTER
fontFormatthis property is used for font formatFontFormat.NORMAL

© danimaniArqsoft


  1. Fluent Interface, Martin Fowler on December twenty of 2005 write about a certain style of interface which he decided to name fluent interface. We write DSL's based on the concept of Fluent Interface