Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int scaleX[] = { 0, 10, 20, 30, 40, 50 };
- int scaleY[] = { 0, 20, 40, 60, 80, 100 };
- int dataY[] = { 100, 4, 22, 90, 22, 5 };
- int dataX[] = { 5, 12, 25, 38, 42, 50 };
- String title = "Test Graph";
- int gpx[] = { 40, 720 };
- int gpy[] = { 80, 180 };
- BufferedImage image = new BufferedImage(800, 300, BufferedImage.TYPE_INT_ARGB);
- Graphics2D g = (Graphics2D) image.getGraphics();
- g.setColor(Color.GRAY);
- g.fillRect(0, 0, 800, 300);
- g.setColor(Color.DARK_GRAY);
- g.fillRect(10, 10, 780, 280);
- g.setColor(Color.GRAY);
- g.fillRect(20, 20, 760, 35);
- g.setColor(Color.BLACK);
- g.setFont(new Font("Arial", Font.PLAIN, 26));
- g.drawString(title, 25, 45);
- g.setColor(Color.GRAY);
- g.fillRect(20, 60, 760, 220);
- g.setColor(Color.LIGHT_GRAY);
- g.fillRect(40, 80, 720, 180);
- // Draw X-Scale (Also draws lines)
- g.setColor(Color.BLACK);
- g.setFont(new Font("Arial", Font.PLAIN, 14));
- int sx = (gpx[1] - gpx[0]) / (scaleX.length - 1);
- for (int i = 0; i < scaleX.length; i++) {
- String label = scaleX[i] + "";
- g.drawString(label, gpx[0] + (sx * i) + 5, gpy[1] + 95);
- g.drawLine(gpx[0] + (sx * i) + 10, gpy[1] + 80, gpx[0] + (sx * i) + 10, gpy[0]);
- }
- // Draw Y-Scale (Also draws lines)
- g.setColor(Color.BLACK);
- g.setFont(new Font("Arial", Font.PLAIN, 14));
- int sy = ((gpy[1] - gpy[0]) / (scaleY.length - 1)) + 14;
- for (int i = 0; i < scaleY.length; i++) {
- String label = scaleY[i] + "";
- g.drawString(label, gpx[0] - 20, gpy[1] - (sy * i) + 80);
- g.drawLine(gpx[0], gpy[1] - (sy * i) + 75, gpx[1] + 40, gpy[1] - (sy * i) + 75);
- }
Advertisement
Add Comment
Please, Sign In to add comment