question: public BufferedImage createGraphFromScores ( int [ ] scores , int [ ] chartSlices ) { BufferedImage bi = new BufferedImage ( WIDTH , HEIGHT , BufferedImage . TYPE_INT_RGB ) ; Graphics2D g2d = bi . createGraphics ( ) ; RenderingHints renderHints = new RenderingHints ( RenderingHints . KEY_ANTIALIASING , RenderingHints . VALUE_ANTIALIAS_ON ) ; g2d . setRenderingHints ( renderHints ) ; g2d . setColor ( Color . white ) ; g2d . fill ( graphRect ) ; g2d . setColor ( Color . black ) ; borderRect . setLocation ( 1 , 1 ) ; g2d . draw ( borderRect ) ; borderRect . setLocation ( ( WIDTH / 2 ) + 1 , 1 ) ; g2d . draw ( borderRect ) ; int x_pie = innerOffset ; int y_pie = innerOffset ; int border = 20 ; Ellipse2D . Double elb = new Ellipse2D . Double ( x_pie - border / 2 , y_pie - border / 2 , pieWidth + border , pieHeight + border ) ; g2d . setColor ( dropShadow ) ; g2d . fill ( elb ) ; g2d . setColor ( Color . black ) ; g2d . draw ( elb ) ; int startAngle = 0 ; int legendWidth = 20 ; int x_legendText = halfWidth + innerOffset / 2 + legendWidth + 5 ; int x_legendBar = halfWidth + innerOffset / 2 ; int textHeight = 20 ; int curElement = 0 ; int y_legend = 0 ; Dimension legendDim = new Dimension ( legendWidth , textHeight / 2 ) ; Rectangle legendRect = new Rectangle ( legendDim ) ; int lastElement = chartSlices . length ; float numberOfScores = 0 ; for ( int i = 0 ; i < scores . length ; i ++ ) { numberOfScores += 1 ; } if ( scores == null || numberOfScores == 0 ) { int sweepAngle = 360 ; g2d . setColor ( Color . GRAY ) ; g2d . fillArc ( x_pie , y_pie , pieWidth , pieHeight , startAngle , sweepAngle ) ; y_legend = curElement * textHeight + innerOffset ; String display = "No dispositions for" ; g2d . setColor ( Color . black ) ; g2d . drawString ( display , x_legendText , y_legend ) ; curElement ++ ; y_legend = curElement * textHeight + innerOffset ; display = "this date range." ; g2d . setColor ( Color . black ) ; g2d . drawString ( display , x_legendText , y_legend ) ; return bi ; } else { float [ ] floatScores = convertIntToFloatArray ( scores ) ; float [ ] scoresPerSlice = calcScorePerSlice ( chartSlices , floatScores ) ; for ( int i = 0 ; i < chartSlices . length ; i ++ ) { float perc = ( scoresPerSlice [ i ] / numberOfScores ) ; int sweepAngle = ( int ) ( perc * 360 ) ; if ( i == lastElement ) { sweepAngle = 360 - startAngle ; } g2d . setColor ( getPieColor ( ) ) ; g2d . fillArc ( x_pie , y_pie , pieWidth , pieHeight , startAngle , sweepAngle ) ; startAngle += sweepAngle ; y_legend = curElement * textHeight + innerOffset ; String display = null ; if ( i == 0 ) { display = "100 - " + chartSlices [ 0 ] ; } else { display = chartSlices [ i - 1 ] - 1 + " - " + chartSlices [ i ] ; } g2d . setColor ( Color . black ) ; g2d . drawString ( display , x_legendText , y_legend ) ; display = "" + ( int ) scoresPerSlice [ i ] ; g2d . setColor ( Color . black ) ; g2d . drawString ( display , x_legendText + 80 , y_legend ) ; display = " (" + ( int ) ( perc * 100 ) + "%)" ; g2d . setColor ( Color . black ) ; g2d . drawString ( display , x_legendText + 110 , y_legend ) ; g2d . setColor ( getPieColor ( ) ) ; legendRect . setLocation ( x_legendBar , y_legend - textHeight / 2 ) ; g2d . fill ( legendRect ) ; setNewColor ( ) ; curElement ++ ; } return bi ; } }
target:  generates a pie chart buffered image using an array of scores and a clices array whos length determines the number of slices, and whos element values determines the ranges of scores per  slice 