Index: trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.impl/src/main/java/org/gvsig/fmap/dal/swing/impl/actions/GraphAction.java
===================================================================
--- trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.impl/src/main/java/org/gvsig/fmap/dal/swing/impl/actions/GraphAction.java	(revision 0)
+++ trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.impl/src/main/java/org/gvsig/fmap/dal/swing/impl/actions/GraphAction.java	(revision 46052)
@@ -0,0 +1,215 @@
+package org.gvsig.fmap.dal.swing.impl.actions;
+
+import java.awt.Dimension;
+import java.awt.event.ActionEvent;
+import java.util.ArrayList;
+import java.util.List;
+import javax.json.JsonArray;
+import javax.json.JsonObject;
+import javax.json.JsonValue;
+import javax.swing.AbstractAction;
+import javax.swing.Action;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.event.ListSelectionListener;
+import org.apache.commons.lang3.StringUtils;
+import org.gvsig.expressionevaluator.Expression;
+import org.gvsig.featureform.swing.JFeaturesForm;
+import org.gvsig.featureform.swing.impl.DefaultJFeaturesForm;
+import org.gvsig.fmap.dal.DataStore;
+import org.gvsig.fmap.dal.feature.Feature;
+import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
+import org.gvsig.fmap.dal.feature.FeatureQuery;
+import org.gvsig.fmap.dal.feature.FeatureQueryOrder;
+import org.gvsig.fmap.dal.feature.FeatureSet;
+import org.gvsig.fmap.dal.feature.FeatureStore;
+import org.gvsig.fmap.dal.swing.AbstractDALActionFactory;
+import org.gvsig.fmap.dal.swing.DALSwingLocator;
+import org.gvsig.fmap.dal.swing.DataSwingManager;
+import org.gvsig.fmap.dal.swing.searchpanel.FeatureStoreSearchPanel;
+import org.gvsig.tools.ToolsLocator;
+import org.gvsig.tools.i18n.I18nManager;
+import org.gvsig.tools.swing.api.ToolsSwingLocator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.gvsig.fmap.dal.swing.DALActionFactory;
+import org.gvsig.fmap.dal.swing.DALActionFactory.DALActionContext;
+import org.gvsig.fmap.dal.swing.impl.searchpanel.DefaultSearchPanel;
+import org.gvsig.fmap.dal.swing.impl.searchpanel.DefaultSearchPanel.SearchActionContext;
+import org.gvsig.tools.swing.api.windowmanager.WindowManager;
+import org.jfree.chart.ChartFactory;
+import org.jfree.chart.ChartPanel;
+import org.jfree.chart.JFreeChart;
+import org.jfree.chart.plot.PlotOrientation;
+import org.jfree.data.category.DefaultCategoryDataset;
+
+/**
+ *
+ * @author jjdelcerro
+ */
+@SuppressWarnings("UseSpecificCatch")
+public class GraphAction 
+        extends AbstractAction 
+        implements ListSelectionListener
+    {
+    
+    private class svDefaultCategoryDataset extends DefaultCategoryDataset {
+
+        public svDefaultCategoryDataset() {
+            
+        }
+    }
+    
+    public static class GraphActionFactory extends AbstractDALActionFactory {
+
+        public static final String ACTION_NAME = "Graph";
+        
+        public GraphActionFactory() {
+            super(ACTION_NAME);
+        }
+
+        @Override
+        public Action createAction(DALActionContext context) {
+            return new GraphAction(context);
+        }
+        
+        
+        
+//        public static void selfRegister() {
+//            DataSwingManager dalSwingManager = DALSwingLocator.getSwingManager();
+//            dalSwingManager.registerFeatureStoreSearchAction(new ShowFormActionFactory());
+//            String[][] iconNames = new String[][]{
+//                new String[]{"dalswing", "search-action-showform"}
+//            };
+//            IconTheme theme = ToolsSwingLocator.getIconThemeManager().getCurrent();
+//            for (String[] icon : iconNames) {
+//                URL url = ShowFormAction.class.getResource(icon[1] + ".png");
+//                theme.registerDefault("DALSwing", icon[0], icon[1], null, url);
+//            }
+//        }
+
+        @Override
+        public boolean isApplicable(Object... args) {
+            return false; // args[0] instanceof SearchActionContext;
+        }
+        
+    }
+
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(ShowFormAction.class);
+    
+    private final DALActionContext context;
+    private boolean showFormSingleElement;
+
+    public GraphAction(DALActionContext context) {
+        this.context = context;
+        I18nManager i18n = ToolsLocator.getI18nManager();
+        this.putValue(
+                Action.ACTION_COMMAND_KEY, 
+                GraphActionFactory.ACTION_NAME
+        );
+        this.putValue(
+                Action.SHORT_DESCRIPTION, 
+                i18n.getTranslation("_Show_graph")
+        );
+        this.putValue(
+                Action.SMALL_ICON, 
+                ToolsSwingLocator.getIconThemeManager().getCurrent().get("chart")
+        );
+        try {
+            this.showFormSingleElement = true;
+            DataStore store = this.context.getStore();
+            if( !(store instanceof FeatureStore) ) {
+                return;
+            }
+            FeatureStore featureStore = (FeatureStore) store;
+            FeatureAttributeDescriptor[] pks = featureStore.getDefaultFeatureType().getPrimaryKey();
+            if (pks == null || pks.length < 1) {
+                this.showFormSingleElement = false;
+            }
+        } catch (Exception ex) {
+        }        
+    }
+    
+    @Override
+    public void actionPerformed(ActionEvent e) {
+        try {
+            this.setEnabled(false);
+            DataStore store = this.context.getStore();
+            if( !(store instanceof FeatureStore) ) {
+                return ;
+            }
+            FeatureStore featureStore = (FeatureStore) store;
+            FeatureQuery query = this.context.getQuery();
+            
+            svDefaultCategoryDataset dataset = new svDefaultCategoryDataset();
+            FeatureSet features = featureStore.getFeatureSet(query);
+
+            Iterable<FeatureQueryOrder.FeatureQueryOrderMember> orderMembers = query.getOrder().members();
+            ArrayList<String> fields = new ArrayList<>();
+            for (FeatureQueryOrder.FeatureQueryOrderMember orderMember : orderMembers) {
+                fields.add(orderMember.getAttributeName());
+            }
+            if (fields.size()<2) {
+                return;
+            }
+            
+            fields.add((String) this.context.getQuery().getAggregateFunctions().keySet().toArray()[0]);
+            
+            String field1 = fields.get(0);
+            String field2 = fields.get(1);
+            String fieldValue = fields.get(2);
+            
+            for (Feature feature : features) {
+                Object value = feature.get(fieldValue);
+                if (value instanceof Number) {
+                    String valueField1;
+                    String valueField2;
+                    if(feature.getType().getAttributeDescriptor(field1)!=null) {
+                        valueField1 = feature.getLabelOfValue(field1);
+                    } else {
+                        valueField1 = feature.get(field1).toString();
+                    }
+                    if(feature.getType().getAttributeDescriptor(field2)!=null) {
+                        valueField2 = feature.getLabelOfValue(field2);
+                    } else {
+                        valueField2 = feature.get(field1).toString();
+                    }
+                    
+                    dataset.addValue((Number) value, valueField1, valueField2);
+                }
+            }
+            
+            JFreeChart barChart = ChartFactory.createBarChart(
+                    field1 + " " + field2,
+                    field2,
+                    fieldValue,
+                    dataset,
+                    PlotOrientation.VERTICAL,
+                    true,
+                    true,
+                    false);
+            ChartPanel chartPanel = new ChartPanel(barChart);
+            chartPanel.setPreferredSize(new Dimension( 360 , 200 ));
+            ToolsSwingLocator.getWindowManager().showWindow(chartPanel, "title", WindowManager.MODE.DIALOG);
+            
+            
+        } catch (Exception ex) {
+            LOGGER.warn("Can't show form", ex);
+        } finally {
+            this.setEnabled(true);
+        }
+    }
+    
+    @Override
+    public void valueChanged(ListSelectionEvent e) {
+        if (e.getValueIsAdjusting()) {
+            return;
+        }
+        if (this.context.getSelectedsCount()== 0) {
+            this.setEnabled(true);
+            return;
+        }
+        this.setEnabled(showFormSingleElement);
+    }
+    
+}
Index: trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.impl/pom.xml
===================================================================
--- trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.impl/pom.xml	(revision 46051)
+++ trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.impl/pom.xml	(revision 46052)
@@ -175,6 +175,12 @@
             <artifactId>org.gvsig.fmap.dal.file.shp</artifactId>
             <scope>runtime</scope>
         </dependency>
+        <dependency>
+            <groupId>org.jfree</groupId>
+            <artifactId>jfreechart</artifactId>
+            <version>1.0.14</version>
+            <scope>compile</scope>
+        </dependency>
     </dependencies>
 
 </project>
Index: trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/programming/CreateChartPanelFunction.java
===================================================================
--- trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/programming/CreateChartPanelFunction.java	(revision 0)
+++ trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/programming/CreateChartPanelFunction.java	(revision 46052)
@@ -0,0 +1,95 @@
+package org.gvsig.expressionevaluator.impl.function.programming;
+
+import java.awt.Dimension;
+import java.awt.Graphics2D;
+import java.awt.image.BufferedImage;
+import javax.json.JsonArray;
+import javax.json.JsonObject;
+import javax.json.JsonValue;
+import org.apache.commons.lang3.Range;
+import org.apache.commons.lang3.StringUtils;
+import org.gvsig.expressionevaluator.Function;
+import org.gvsig.expressionevaluator.Interpreter;
+import org.gvsig.expressionevaluator.spi.AbstractFunction;
+import org.gvsig.expressionevaluator.spi.JsonUtils;
+import org.jfree.chart.ChartFactory;
+import org.jfree.chart.ChartPanel;
+import org.jfree.chart.ChartUtilities;
+import org.jfree.chart.JFreeChart;
+import org.jfree.chart.plot.PlotOrientation;
+import org.jfree.data.category.DefaultCategoryDataset;
+
+public class CreateChartPanelFunction extends AbstractFunction {
+
+    public CreateChartPanelFunction() {
+        super(
+            Function.GROUP_PROGRAMMING, 
+            "CREATE_CHARTPANEL", 
+            Range.is(1),
+            "",
+            "CREATE_CHARTPANEL"+"({{string}})",
+            null,
+            "ChartPanel",
+            false
+        );
+    }
+    
+    @Override
+    public boolean allowConstantFolding() {
+        return false;
+    }    
+    
+    @Override
+    public Object call(Interpreter interpreter, final Object[] args) throws Exception {
+        Object obj = getObject(args, 0);
+        if( obj == null ) {
+            return null;
+            //throw new ExpressionRuntimeException("Null is not valid in "+FUNCTION_GETITEM+" function.");
+        }
+        
+        if( !(obj instanceof JsonObject )) {
+            obj = JsonUtils.toJsonObject(obj);
+        }
+        
+        JsonObject jsonobj = ((JsonObject)obj);
+        ChartPanel graph = createGraph(jsonobj);
+        return graph;
+        
+    }
+    
+
+    public ChartPanel createGraph(JsonObject json) {
+        String chartType = json.getString("chartType").toLowerCase();
+        switch(chartType){
+            case "barchart": {
+                JsonArray datasetJson = json.getJsonArray("dataset");
+                DefaultCategoryDataset ds = new DefaultCategoryDataset();
+                for (JsonValue jsonValue : datasetJson) {
+                    JsonArray element = (JsonArray) jsonValue;
+                    double value = element.getJsonNumber(0).doubleValue();
+                    String field1 = element.getString(1, null);
+                    String field2 = element.getString(2, null);
+                    ds.addValue(value, field1, field2);
+                }
+                JFreeChart barChart = ChartFactory.createBarChart(
+                            json.getString("title", ""),
+                            json.getString("categoryAxisLabel",""),
+                            json.getString("valueAxisLabel",""),
+                            ds,
+                            StringUtils.equalsIgnoreCase(json.getString("orientation",null),"HORIZONTAL")? PlotOrientation.HORIZONTAL:PlotOrientation.VERTICAL,
+                            json.getBoolean("legend", true),
+                            false,
+                            false);
+		
+                ChartPanel chartPanel = new ChartPanel(barChart);
+                chartPanel.setPreferredSize(new Dimension( json.getInt("witdh",360) , json.getInt("height",200) ));
+                return chartPanel;
+            }
+            default: 
+                throw new IllegalArgumentException("Unknown chart type:" + chartType);
+                
+                
+        }
+    }
+
+}
Index: trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/programming/CreateChartFunction.java
===================================================================
--- trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/programming/CreateChartFunction.java	(revision 0)
+++ trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/programming/CreateChartFunction.java	(revision 46052)
@@ -0,0 +1,102 @@
+package org.gvsig.expressionevaluator.impl.function.programming;
+
+import java.awt.Dimension;
+import java.awt.Graphics2D;
+import java.awt.Image;
+import java.awt.image.BufferedImage;
+import javax.json.JsonArray;
+import javax.json.JsonObject;
+import javax.json.JsonValue;
+import org.apache.commons.lang3.Range;
+import org.apache.commons.lang3.StringUtils;
+import org.gvsig.expressionevaluator.Function;
+import org.gvsig.expressionevaluator.Interpreter;
+import org.gvsig.expressionevaluator.spi.AbstractFunction;
+import org.gvsig.expressionevaluator.spi.JsonUtils;
+import org.gvsig.tools.swing.api.SimpleImage;
+import org.gvsig.tools.swing.api.ToolsSwingLocator;
+import org.jfree.chart.ChartFactory;
+import org.jfree.chart.ChartPanel;
+import org.jfree.chart.JFreeChart;
+import org.jfree.chart.plot.PlotOrientation;
+import org.jfree.data.category.DefaultCategoryDataset;
+
+public class CreateChartFunction extends AbstractFunction {
+
+    public CreateChartFunction() {
+        super(
+            Function.GROUP_PROGRAMMING, 
+            "CREATE_CHART", 
+            Range.is(1),
+            "",
+            "CREATE_CHART"+"({{string}})",
+            null,
+            "SimpleImage",
+            false
+        );
+    }
+    
+    @Override
+    public boolean allowConstantFolding() {
+        return false;
+    }    
+    
+    @Override
+    public Object call(Interpreter interpreter, final Object[] args) throws Exception {
+        Object obj = getObject(args, 0);
+        if( obj == null ) {
+            return null;
+            //throw new ExpressionRuntimeException("Null is not valid in "+FUNCTION_GETITEM+" function.");
+        }
+        
+        if( !(obj instanceof JsonObject )) {
+            obj = JsonUtils.toJsonObject(obj);
+        }
+        
+        JsonObject jsonobj = ((JsonObject)obj);
+        SimpleImage graph = ToolsSwingLocator.getToolsSwingManager().createSimpleImage(createGraph(jsonobj));
+        return graph;
+        
+    }
+    
+
+    public Image createGraph(JsonObject json) {
+        String chartType = json.getString("chartType").toLowerCase();
+        switch(chartType){
+            case "barchart": {
+                JsonArray datasetJson = json.getJsonArray("dataset");
+                DefaultCategoryDataset ds = new DefaultCategoryDataset();
+                for (JsonValue jsonValue : datasetJson) {
+                    JsonArray element = (JsonArray) jsonValue;
+                    double value = element.getJsonNumber(0).doubleValue();
+                    String field1 = element.getString(1, null);
+                    String field2 = element.getString(2, null);
+                    ds.addValue(value, field1, field2);
+                }
+                JFreeChart barChart = ChartFactory.createBarChart(
+                            json.getString("title", ""),
+                            json.getString("categoryAxisLabel",""),
+                            json.getString("valueAxisLabel",""),
+                            ds,
+                            StringUtils.equalsIgnoreCase(json.getString("orientation",null),"HORIZONTAL")? PlotOrientation.HORIZONTAL:PlotOrientation.VERTICAL,
+                            json.getBoolean("legend", true),
+                            false,
+                            false);
+		
+                ChartPanel chartPanel = new ChartPanel(barChart);
+                chartPanel.setPreferredSize(new Dimension( json.getInt("witdh",360) , json.getInt("height",200) ));
+		Dimension d = chartPanel.getSize();
+		BufferedImage image = new BufferedImage(d.width, d.height, BufferedImage.TYPE_INT_RGB);
+		Graphics2D g2d = image.createGraphics();
+		chartPanel.print( g2d );
+		g2d.dispose();
+                return image;
+            }
+            default: 
+                throw new IllegalArgumentException("Unknown chart type:" + chartType);
+                
+                
+        }
+    }
+
+}
Index: trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/pom.xml
===================================================================
--- trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/pom.xml	(revision 46051)
+++ trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/pom.xml	(revision 46052)
@@ -56,6 +56,12 @@
           <scope>test</scope>
         </dependency>
         <dependency>
+            <groupId>org.jfree</groupId>
+            <artifactId>jfreechart</artifactId>
+            <version>1.0.14</version>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
             <groupId>net.sf.cssbox</groupId>
             <artifactId>cssbox</artifactId>
             <version>5.0.0</version>
