← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10738: Impl support for area charts for PNG version

 

------------------------------------------------------------
revno: 10738
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2013-05-02 14:31:26 +0200
message:
  Impl support for area charts for PNG version
modified:
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java	2013-04-30 12:40:20 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java	2013-05-02 12:31:26 +0000
@@ -68,6 +68,7 @@
 import org.jfree.chart.plot.PiePlot;
 import org.jfree.chart.plot.PlotOrientation;
 import org.jfree.chart.plot.ValueMarker;
+import org.jfree.chart.renderer.category.AreaRenderer;
 import org.jfree.chart.renderer.category.BarRenderer;
 import org.jfree.chart.renderer.category.CategoryItemRenderer;
 import org.jfree.chart.renderer.category.LineAndShapeRenderer;
@@ -483,6 +484,23 @@
     }
 
     /**
+     * Returns an area renderer.
+     * 
+     * TODO centralize these renderer methods.
+     */
+    private AreaRenderer getAreaRenderer()
+    {
+        AreaRenderer renderer = new AreaRenderer();
+
+        for ( int i = 0; i < colors.length; i++ )
+        {
+            renderer.setSeriesPaint( i, colors[i] );
+        }
+
+        return renderer;
+    }
+
+    /**
      * Returns a horizontal line marker for the given x value and label.
      */
     private Marker getMarker( Double value, String label )
@@ -513,7 +531,7 @@
 
         CategoryDataset[] dataSets = getCategoryDataSet( chart );
 
-        if ( chart.isType( TYPE_LINE ) || chart.isType( TYPE_AREA ) )
+        if ( chart.isType( TYPE_LINE ) )
         {
             plot = new CategoryPlot( dataSets[0], new CategoryAxis(), new NumberAxis(), lineRenderer );
             plot.setOrientation( PlotOrientation.VERTICAL );
@@ -528,6 +546,10 @@
             plot = new CategoryPlot( dataSets[0], new CategoryAxis(), new NumberAxis(), barRenderer );
             plot.setOrientation( PlotOrientation.HORIZONTAL );
         }
+        else if ( chart.isType( TYPE_AREA ) )
+        {
+            return getAreaChart( chart, dataSets[0] );
+        }
         else if ( chart.isType( TYPE_PIE ) )
         {
             return getMultiplePieChart( chart, dataSets );
@@ -591,6 +613,28 @@
         return jFreeChart;
     }
 
+    private JFreeChart getAreaChart( Chart chart, CategoryDataset dataSet )
+    {
+        JFreeChart areaChart = ChartFactory.createAreaChart( chart.getName(), chart.getDomainAxisLabel(), 
+            chart.getRangeAxisLabel(), dataSet, PlotOrientation.VERTICAL, true, false, false );
+        
+        CategoryPlot plot = (CategoryPlot) areaChart.getPlot();
+        plot.setBackgroundPaint( Color.WHITE );
+        plot.setOutlinePaint( Color.WHITE );
+        plot.setOrientation( PlotOrientation.VERTICAL );
+        plot.setRenderer( getAreaRenderer() );
+        
+        CategoryAxis xAxis = plot.getDomainAxis();
+        xAxis.setCategoryLabelPositions( CategoryLabelPositions.UP_45 );
+        xAxis.setLabelFont( labelFont );
+        
+        areaChart.getTitle().setFont( titleFont );
+        areaChart.addSubtitle( getSubTitle( chart ) );
+        areaChart.setAntiAlias( true );
+        
+        return areaChart;
+    }
+    
     private JFreeChart getStackedBarChart( Chart chart, CategoryDataset dataSet, boolean horizontal )
     {
         JFreeChart stackedBarChart = null;