|
charting5.b.java |
|
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 5b");
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 // glyph coordinates are pairs of XY doubles
22 double [] glyph = new double [] {
23 -0.10, 0.0,
24 0.10, 0.0,
25 0.0, 0.16
26 };
27 GlyphBarValueSet gb = new GlyphBarValueSet("JVM Performance", 1.0, 0x0,
28 vals, 0xff8888, 0.25, glyph, 0.20);
29 page.appendValues(gb);
30 gb.setRange(0.0, 10.0, 0.0);
31 page.drawMain(1.5, 7.0, 6.5, 3.0, 36, 4, 0xdddddd, 2.0, 0x0);
32 page.close();
33 }
34
35 }
36
37 class GlyphBarValueSet extends ValueSet {
38
39 private int barColor;
40 private double barWidth;
41 private double [] glyphCoords;
42 private double pitch;
43
44 public GlyphBarValueSet(String name, double lineThickness, int lineColor,
45 double [] values, int barColor, double barWidth,
46 double [] glyphCoords, double pitch) {
47 super(name, lineThickness, lineColor, values);
48 this.barColor = barColor;
49 this.barWidth = barWidth;
50 this.glyphCoords = glyphCoords;
51 this.pitch = pitch;
52 }
53
54 public int getFillColor() {
55 return barColor;
56 }
57
58 public double getBarWidth() {
59 return barWidth;
60 }
61
62 public void setBarWidth(double barWidth) {
63 this.barWidth = barWidth;
64 }
65
66 public void render(ChartGraphics chart) {
67 chart.setLineColor(this.getLineColor());
68 chart.setLineWidth(this.getLineThickness());
69 chart.setFillColor(this.getFillColor());
70 int j = this.getValueCount();
71 double incr = chart.getWidth() / (j + 1);
72 this.setScale(chart.getHeight());
73 double yAxis = chart.getYLocation() + this.getBaseValue();
74 double x = chart.getXLocation() - this.getBarWidth() / 2.0;
75 double x2 = x + this.getBarWidth();
76 int n = 0;
77 while (j-- > 0) {
78 chart.fillRect(x += incr, yAxis, x2 += incr, yAxis + this.getNextValue());
79 }
80 }
81
82 public void sample(ChartGraphics chart, double x, double cx, double y, double size) {
83 chart.setLineColor(this.getLineColor());
84 chart.setLineWidth(this.getLineThickness());
85 chart.setFillColor(this.getFillColor());
86 chart.fillRect(cx - size, y - size, cx + size, y + size);
87 }
88
89 }
|
charting5.b.java |
|