1 package JSci.awt; 2 3 import java.awt.*; 4 5 11 public class LayeredBarGraph extends BarGraph { 12 15 public LayeredBarGraph(CategoryGraph2DModel gm) { 16 super(gm); 17 } 18 21 protected void drawBars(Graphics g) { 22 int numSeries=1; 24 model.firstSeries(); 25 while(model.nextSeries()) 26 numSeries++; 27 if(numSeries==1) { 28 for(int i=0;i<model.seriesLength();i++) { 29 drawBar(g, i, model.getValue(i), barColor[0]); 30 } 31 } else { 32 float seriesValue[]=new float[numSeries]; 33 Color seriesColor[]=new Color[numSeries]; 34 for(int i=0;i<model.seriesLength();i++) { 35 model.firstSeries(); 36 for(int j=0;j<numSeries;j++) { 37 seriesValue[j]=model.getValue(i); 38 seriesColor[j]=barColor[j]; 39 model.nextSeries(); 40 } 41 float val; 43 Color col; 44 for(int k,j=1;j<numSeries;j++) { 45 val=seriesValue[j]; 46 col=seriesColor[j]; 47 for(k=j-1;k>=0 && seriesValue[k]<val;k--) { 48 seriesValue[k+1]=seriesValue[k]; 49 seriesColor[k+1]=seriesColor[k]; 50 } 51 seriesValue[k+1]=val; 52 seriesColor[k+1]=col; 53 } 54 for(int j=0;j<numSeries;j++) 56 drawBar(g, i, seriesValue[j], seriesColor[j]); 57 } 58 } 59 } 60 63 private void drawBar(Graphics g, int pos, float value, Color color) { 64 Point p; 65 if(value<0.0f) 66 p=dataToScreen(pos,0.0f); 67 else 68 p=dataToScreen(pos,value); 69 g.setColor(color); 70 final int dy=Math.abs(p.y-origin.y); 71 g.fillRect(p.x+barPad, p.y, barWidth, dy); 72 g.setColor(Color.black); 73 g.drawRect(p.x+barPad, p.y, barWidth, dy); 74 } 75 } 76 77 | Popular Tags |