1 34 35 package org.krysalis.jcharts.axisChart; 36 37 38 import org.krysalis.jcharts.chartData.interfaces.IAxisChartDataSet; 39 import org.krysalis.jcharts.imageMap.ImageMapNotSupportedException; 40 import org.krysalis.jcharts.properties.DataAxisProperties; 41 42 import java.awt.*; 43 import java.awt.geom.Area ; 44 import java.awt.geom.GeneralPath ; 45 46 47 52 abstract class StackedAreaChart 53 { 54 55 61 static void render( AxisChart axisChart, IAxisChartDataSet iAxisChartDataSet ) 62 { 63 if( axisChart.getImageMap() != null ) 65 { 66 throw new ImageMapNotSupportedException( "HTML client-side image maps are not supported on Area Charts." ); 67 } 68 69 71 float xPosition=axisChart.getXAxis().getTickStart(); 72 73 GeneralPath generalPaths[]=new GeneralPath [ iAxisChartDataSet.getNumberOfDataSets() ]; 74 75 76 79 DataAxisProperties dataAxisProperties= (DataAxisProperties) axisChart.getAxisProperties().getYAxisProperties(); 81 82 83 float stackedValue=0f; 84 85 86 for( int i=0; i < generalPaths.length; i++ ) 90 { 91 generalPaths[ i ]=new GeneralPath (); 92 93 generalPaths[ i ].moveTo( xPosition, axisChart.getYAxis().getZeroLineCoordinate() ); 94 95 stackedValue+=iAxisChartDataSet.getValue( i, 0 ); 96 generalPaths[ i ].lineTo( xPosition, axisChart.getYAxis().computeAxisCoordinate( axisChart.getYAxis().getOrigin(), 97 stackedValue, 98 axisChart.getYAxis().getScaleCalculator().getMinValue() ) ); 99 } 100 101 for( int j=1; j < iAxisChartDataSet.getNumberOfDataItems(); j++ ) 103 { 104 xPosition+=axisChart.getXAxis().getScalePixelWidth(); 105 106 stackedValue=0f; 107 108 for( int i=0; i < generalPaths.length; i++ ) 110 { 111 stackedValue+=iAxisChartDataSet.getValue( i, j ); 112 generalPaths[ i ].lineTo( xPosition, axisChart.getYAxis().computeAxisCoordinate( axisChart.getYAxis().getOrigin(), 113 stackedValue, 114 axisChart.getYAxis().getScaleCalculator().getMinValue() ) ); 115 } 116 } 117 118 119 Area [] areas=new Area [ generalPaths.length ]; 120 121 Area totalArea=null; 122 Area newArea; 123 124 125 for( int i=0; i < generalPaths.length; i++ ) 128 { 129 generalPaths[ i ].lineTo( xPosition, axisChart.getYAxis().getZeroLineCoordinate() ); 130 131 generalPaths[ i ].closePath(); 132 134 newArea=new Area ( generalPaths[ i ] ); 135 136 if( i > 0 ) 138 { 139 areas[ i ]=(Area ) newArea.clone(); 140 areas[ i ].subtract( totalArea ); 141 142 totalArea=newArea; 143 } 144 else 145 { 146 areas[ 0 ]=newArea; 147 totalArea=areas[ 0 ]; 148 } 149 } 150 151 152 Graphics2D g2d=axisChart.getGraphics2D(); 153 154 for( int i=0; i < areas.length; i++ ) 157 { 158 g2d.setPaint( iAxisChartDataSet.getPaint( i ) ); 159 g2d.fill( areas[ i ] ); 161 } 162 } 163 164 } 165 | Popular Tags |