package color;
public class pro {
int datanumber;
double[] x=new double[100];
public static void main(String[] args) {
pro r=new pro();
}
pro(){
datanumber=5;
x[1]=100;
x[2]=200;
x[3]=50;
x[4]=300;
x[5]=20;
graph sub=new graph();
sub.datanumber=datanumber;
sub.x=x;
sub.makedata("ren.jpg");
}
}
package color;
import java.awt.*;
import java.awt.Color;
import java.awt.image.*;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.ImageIO;
import java.awt.Polygon;
public class graph {
int datanumber;
double[] x=new double[100];
void makedata(String file){
BufferedImage off = new BufferedImage(500, 500, BufferedImage.TYPE_INT_BGR);
Graphics offsc = off.getGraphics();
int s;
double minx,maxx;
minx=10000;
maxx=0;
for(s=1;s<datanumber+1;s++){
if(x[s]>maxx)maxx=x[s];
if(x[s]<minx)minx=x[s];
}
String str1=""+maxx;
String str2=""+minx;
int delta=400/datanumber;
offsc.setColor(Color.white);
offsc.fillRect(0,0,500,500);
offsc.setColor(Color.black);
offsc.drawLine(50,450,50,50);
offsc.drawLine(50,450,450,450);
offsc.drawString(str1,50,50);
offsc.drawString(str2,50,450);
for(s=1;s<datanumber;s++){
int y1=(int)(400*(x[s]-minx)/(maxx-minx));
int y2=(int)(400*(x[s+1]-minx)/(maxx-minx));
offsc.drawLine(delta*(s-1)+50,450-y1,delta*s+50,450-y2);
}
offsc.dispose();
try {
ImageIO.write(off, "jpeg", new File(file));
} catch (IOException exception) { exception.printStackTrace(); }
}
}
最終更新:2015年09月20日 06:00