关于图形的 我想画一条x轴代表时间y轴代表高度 ,随x轴时间变化,y轴高度不断变化的曲线图。请问java下有没有这样的类——画曲线图的类。请帮我举个例子。先谢谢了,我在公司正急用!!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 网上的一个例子:http://dev.csdn.net/develop/article/26/26759.shtmpackage test;import java.awt.*;import java.awt.geom.*;import java.awt.image.*;import javax.swing.JFrame;import java.lang.Math;/** *曲线图绘制 */public class CurveFrame extends JFrame { /**数据*/ private double[] result; /**数据项名称*/ private String[] title; /**参数:结果集,名称集*/ public CurveFrame(double[] result, String[] title) { this.result = result; this.title = title; } public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; Dimension dim = this.getSize(); g2.setColor(Color.white); g2.fillRect(0, 0, dim.width, dim.height); //写title; Font font = g2.getFont().deriveFont(12.0f); g2.setFont(font); FontMetrics metrics = g2.getFontMetrics(); g2.setPaint(Color.black); g2.drawString(title[0], (dim.width - title[0].length() * 5) / 2, 10); // draw the x and y axis g2.setStroke(new BasicStroke(2.0f)); g2.draw(new Line2D.Double(40, 30, 40, dim.height - 30)); g2.draw(new Line2D.Double(40, dim.height - 30, dim.width - 20, dim.height - 30)); long unit=(Math.round((result[0]+750)/1500))*50; long yMax = result[0] == 0 ? unit : Math.round((result[0]+unit/2)/unit) * unit; int widthPer = (dim.width - 40) / result.length; long heightPer = (dim.height - 60) / (yMax / unit); //draw the y axis scale; g2.setPaint(Color.lightGray); g2.setStroke(new BasicStroke(1.0f)); for (int i = 0; i<=yMax / unit; i++) { g2.draw(new Line2D.Double(40, dim.height - 30 - i * heightPer, dim.width - 40, dim.height - 30 - i * heightPer)); String ylabel = String.valueOf(i * unit); g2.drawString(ylabel, 35 - metrics.stringWidth(ylabel), dim.height - 30 - (i * heightPer)); } //draw x title; GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, result.length - 2); for (int i = 1; i < result.length; i++) { //draw x scale; g2.setPaint(Color.lightGray); g2.setStroke(new BasicStroke(1.0f)); g2.draw(new Line2D.Double(40 + (i - 1) * widthPer, dim.height - 30, 40 + (i - 1) * widthPer,30)); font = g2.getFont().deriveFont(10.0f); g2.setFont(font); g2.setPaint(Color.black); g2.drawString(title[i], 40 + widthPer * (i - 1)-metrics.stringWidth(title[i])/2, dim.height - 10); g2.setPaint(Color.red); g2.setStroke(new BasicStroke(2.0f)); if (i == 1) { path.moveTo(40, Math.round(dim.height - 30 - (result[i] / unit) * heightPer)); } else { path.lineTo(Math.round(widthPer * (i - 1)) + 40, Math.round(dim.height - 30 - (result[i] / unit) * heightPer)); } } g2.draw(path); } } 取Oracle字段注释编码转换的问题 Action中封装的list,如何在IFRAME的子页面中获取? hibernate的问题 请来看 请问i怎样在页面中运行已经编译好的Java类 页面找不到JS文件 为什么我的程序在一次打开100个窗口的时候会出错 关于数据表的更新 eclipse+tomcat,无法显示该网页 新手求救!!!! jdbcTemplate为空求指教 如何修改Cookie里的值 最后10分了,没有办法,超级的考试题目
http://dev.csdn.net/develop/article/26/26759.shtm
package test;import java.awt.*;import java.awt.geom.*;import java.awt.image.*;import javax.swing.JFrame;import java.lang.Math;/** *曲线图绘制 */public class CurveFrame extends JFrame { /**数据*/ private double[] result; /**数据项名称*/ private String[] title; /**参数:结果集,名称集*/ public CurveFrame(double[] result, String[] title) { this.result = result; this.title = title; } public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; Dimension dim = this.getSize(); g2.setColor(Color.white); g2.fillRect(0, 0, dim.width, dim.height); //写title; Font font = g2.getFont().deriveFont(12.0f); g2.setFont(font); FontMetrics metrics = g2.getFontMetrics(); g2.setPaint(Color.black); g2.drawString(title[0], (dim.width - title[0].length() * 5) / 2, 10); // draw the x and y axis g2.setStroke(new BasicStroke(2.0f)); g2.draw(new Line2D.Double(40, 30, 40, dim.height - 30)); g2.draw(new Line2D.Double(40, dim.height - 30, dim.width - 20, dim.height - 30)); long unit=(Math.round((result[0]+750)/1500))*50; long yMax = result[0] == 0 ? unit : Math.round((result[0]+unit/2)/unit) * unit; int widthPer = (dim.width - 40) / result.length; long heightPer = (dim.height - 60) / (yMax / unit); //draw the y axis scale; g2.setPaint(Color.lightGray); g2.setStroke(new BasicStroke(1.0f)); for (int i = 0; i<=yMax / unit; i++) { g2.draw(new Line2D.Double(40, dim.height - 30 - i * heightPer, dim.width - 40, dim.height - 30 - i * heightPer)); String ylabel = String.valueOf(i * unit); g2.drawString(ylabel, 35 - metrics.stringWidth(ylabel), dim.height - 30 - (i * heightPer)); } //draw x title; GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, result.length - 2); for (int i = 1; i < result.length; i++) { //draw x scale; g2.setPaint(Color.lightGray); g2.setStroke(new BasicStroke(1.0f)); g2.draw(new Line2D.Double(40 + (i - 1) * widthPer, dim.height - 30, 40 + (i - 1) * widthPer,30)); font = g2.getFont().deriveFont(10.0f); g2.setFont(font); g2.setPaint(Color.black); g2.drawString(title[i], 40 + widthPer * (i - 1)-metrics.stringWidth(title[i])/2, dim.height - 10); g2.setPaint(Color.red); g2.setStroke(new BasicStroke(2.0f)); if (i == 1) { path.moveTo(40, Math.round(dim.height - 30 - (result[i] / unit) * heightPer)); } else { path.lineTo(Math.round(widthPer * (i - 1)) + 40, Math.round(dim.height - 30 - (result[i] / unit) * heightPer)); } } g2.draw(path); } }