turt2live

Untitled

Dec 21st, 2011
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.51 KB | None | 0 0
  1. int scaleX[] = { 0, 10, 20, 30, 40, 50 };
  2. int scaleY[] = { 0, 20, 40, 60, 80, 100 };
  3. int dataY[] = { 100, 4, 22, 90, 22, 5 };
  4. int dataX[] = { 5, 12, 25, 38, 42, 50 };
  5. String title = "Test Graph";
  6. int gpx[] = { 40, 720 };
  7. int gpy[] = { 80, 180 };
  8.  
  9. BufferedImage image = new BufferedImage(800, 300, BufferedImage.TYPE_INT_ARGB);
  10. Graphics2D g = (Graphics2D) image.getGraphics();
  11. g.setColor(Color.GRAY);
  12. g.fillRect(0, 0, 800, 300);
  13. g.setColor(Color.DARK_GRAY);
  14. g.fillRect(10, 10, 780, 280);
  15. g.setColor(Color.GRAY);
  16. g.fillRect(20, 20, 760, 35);
  17. g.setColor(Color.BLACK);
  18. g.setFont(new Font("Arial", Font.PLAIN, 26));
  19. g.drawString(title, 25, 45);
  20. g.setColor(Color.GRAY);
  21. g.fillRect(20, 60, 760, 220);
  22. g.setColor(Color.LIGHT_GRAY);
  23. g.fillRect(40, 80, 720, 180);
  24. // Draw X-Scale (Also draws lines)
  25. g.setColor(Color.BLACK);
  26. g.setFont(new Font("Arial", Font.PLAIN, 14));
  27. int sx = (gpx[1] - gpx[0]) / (scaleX.length - 1);
  28. for (int i = 0; i < scaleX.length; i++) {
  29.     String label = scaleX[i] + "";
  30.     g.drawString(label, gpx[0] + (sx * i) + 5, gpy[1] + 95);
  31.     g.drawLine(gpx[0] + (sx * i) + 10, gpy[1] + 80, gpx[0] + (sx * i) + 10, gpy[0]);
  32. }
  33. // Draw Y-Scale (Also draws lines)
  34. g.setColor(Color.BLACK);
  35. g.setFont(new Font("Arial", Font.PLAIN, 14));
  36. int sy = ((gpy[1] - gpy[0]) / (scaleY.length - 1)) + 14;
  37. for (int i = 0; i < scaleY.length; i++) {
  38.     String label = scaleY[i] + "";
  39.     g.drawString(label, gpx[0] - 20, gpy[1] - (sy * i) + 80);
  40.     g.drawLine(gpx[0], gpy[1] - (sy * i) + 75, gpx[1] + 40, gpy[1] - (sy * i) + 75);
  41. }
Advertisement
Add Comment
Please, Sign In to add comment