1     package sutut1;
2     
3     import javax.servlet.*;
4     import javax.servlet.http.*;
5     import java.io.*;
6     import java.util.*;
7     
8     import us.oh.state.common.utility.*;
9     
10    public class charting5 extends HttpServlet {
11    
12      public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
13        response.setContentType("application/pdf");
14        PdfChart page = new PdfChart(response.getOutputStream());
15        page.setTextColor(0x0);
16        page.setFont(page.BOLD, 24);
17        page.println("Tutorial - Charting 5");
18        page.setFont(page.NORMAL, 12);
19        page.println(new Date().toString());
20        double [] vals = new double [] { 3.4, 2.9, 7.5, 4.1, 2.4 };
21        GlyphBarValueSet gb = new GlyphBarValueSet("JVM Performance", 1.0, 0x0,
22          vals, 0xff8888, 0.25);
23        page.appendValues(gb);
24        gb.setRange(0.0, 10.0, 0.0);
25        page.drawMain(1.5, 7.0, 6.5, 3.0, 36, 4, 0xdddddd, 2.0, 0x0);
26        page.close();
27      }
28    
29    }
30    
31    class GlyphBarValueSet extends ValueSet {
32    
33    private int barColor;
34    private double barWidth;
35    public GlyphBarValueSet(String name, double lineThickness, int lineColor,
36        double [] values, int barColor, double barWidth) {
37      super(name, lineThickness, lineColor, values);
38      this.barColor = barColor;
39      this.barWidth = barWidth;
40    }
41    
42    public int getFillColor() {
43      return barColor;
44    }
45    
46    public double getBarWidth() {
47      return barWidth;
48    }
49    
50    public void setBarWidth(double barWidth) {
51      this.barWidth = barWidth;
52    }
53    
54    public void render(ChartGraphics chart) {
55      chart.setLineColor(this.getLineColor());
56      chart.setLineWidth(this.getLineThickness());
57      chart.setFillColor(this.getFillColor());
58      int j = this.getValueCount();
59      double incr = chart.getWidth() / (j + 1);
60      this.setScale(chart.getHeight());
61      double yAxis = chart.getYLocation() + this.getBaseValue();
62      double x = chart.getXLocation() - this.getBarWidth() / 2.0;
63      double x2 = x + this.getBarWidth();
64      int n = 0;
65      while (j-- > 0) {
66        chart.fillRect(x += incr, yAxis, x2 += incr, yAxis + this.getNextValue());
67      }
68    }
69    
70    public void sample(ChartGraphics chart, double x, double cx, double y, double size) {
71      chart.setLineColor(this.getLineColor());
72      chart.setLineWidth(this.getLineThickness());
73      chart.setFillColor(this.getFillColor());
74      chart.fillRect(cx - size, y - size, cx + size, y + size);
75    }
76    
77    }