我有个朋友在炒股票,我看到那些趋势图挺好的,我想向各位高人请教一下,在JSP里可以做出来么?我刚学习JSP没多久,如果能做该如何实现啊?谢了啊!!!
解决方案 »
- 关于include的问题
- 苦思了好长时间的问题,请大侠帮忙,在table中用上下键选数据!!!
- hibernate代码解析
- 向战斗在程序界的精英们致以崇高的问候!
- Tomcat和IIS的奇怪问题
- distinct数据库查询记录数问题,很急,在线等!100分马上送
- 就省这些了!给大家了!
- 在Jbuilder7.0中可以用Struts架构吗?
- (●●●●,高分200)在windows2000和linux下分别如何整合apache、tomcat、jdk使其同时可以运行php和jsp.(在线等待)
- 一个Applet播放器中的问题!急!!!
- [求助]linux中mysqld进程占cpu99????
- 这段代码获得鼠标的位置,但是如果网页有滚动条的话,获得的鼠标位置就不对了
我也很喜欢证券。我国目前最火的预测软件莫过于[指南针]了,最初的[指南针]是使用VB开发的。下面我向你推荐一种比较简单的方式:
JSP调用JavaBean在网页上动态生成柱状图:
//Graphics.jsp
<jsp:useBean id="cg" scope="page" class="tu.ChartGraphics" />
<jsp:useBean id="gd" scope="page" class="tu.GetData" />
<%!
int height[]=new int[5];
%>
<%
height=gd.getHightArray();
cg.graphicsGeneration(height[0],height[1],height[2],height[3],height[4]);
%>
//ChartGraphics.java
package tu;
import java.io.*;
import java.util.*;
import com.sun.image.codec.jpeg.*;
import java.awt.image.*;
import java.awt.*;
public class ChartGraphics {
BufferedImage image;
public void createImage(String fileLocation) {
try {
FileOutputStream fos = new FileOutputStream(fileLocation);
BufferedOutputStream bos = new BufferedOutputStream(fos);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(bos);
encoder.encode(image);
bos.close();
} catch(Exception e) {
System.out.println(e);
}
}
public void graphicsGeneration(int h1,int h2,int h3,int h4,int h5) {
final int X=10;
int imageWidth = 300;//图片的宽度
int imageHeight = 300;//图片的高度
int columnWidth=30;//柱的宽度
int columnHeight=200;//柱的最大高度
ChartGraphics chartGraphics = new ChartGraphics();
chartGraphics.image = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_RGB);
Graphics graphics = chartGraphics.image.getGraphics();
graphics.setColor(Color.white);
graphics.fillRect(0,0,imageWidth,imageHeight);
graphics.setColor(Color.red);
graphics.drawRect(X+1*columnWidth, columnHeight-h1, columnWidth, h1);
graphics.drawRect(X+2*columnWidth, columnHeight-h2, columnWidth, h2);
graphics.drawRect(X+3*columnWidth, columnHeight-h3, columnWidth, h3);
graphics.drawRect(X+4*columnWidth, columnHeight-h4, columnWidth, h4);
graphics.drawRect(X+5*columnWidth, columnHeight-h5, columnWidth, h5);
chartGraphics.createImage("c:\\jsp\\chart.jpg");
}
}
//GetData.java
//读取Text文件中数据的 Java Bean
package tu;
import java.io.*;
public class GetData {
int heightArray[] = new int[5];
public int[] getHightArray() {
try {
RandomAccessFile randomAccessFile = new RandomAccessFile ("c:\\jsp\\ColumnHeightArray.txt","r");
for (int i=0;i<5;i++)
{
heightArray[i] = Integer.parseInt(randomAccessFile.readLine());
}
}
catch(Exception e) {
System.out.println(e);
}
return heightArray;
}
}
//jsp/ColumnHeightArray.txt:
10
200
150
20
100
最后奉劝一句,杀鸡最好不用牛刀。
就是用Graphics Graphics2D等来画的,用起他的画图控件,会有很多问题,等它收费了,等它升级了,什么的,都是很大的问题,而要修改时,又是一个大问题, 兼容性,又是一个大问题.
①设置数值
②设置图片样式
③生成图片
三步搞定,当然里面有些具体的东西要你自己研究去