如何绘制柱状椭圆? 1、用Jfreechart,请参考:http://asp2.6to23.com/sentom/list.asp?id=10 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 String title = "柱状图测试";String domain = "单位比较";String range = "数值";//CategoryDataset data = DemoDatasetFactory.createCategoryDataset();DefaultCategoryDataset data = new DefaultCategoryDataset();for (int r = 0; r < 5; r++) { String rowKey = "单位 [" + (r + 1)+"]" ; //第一层循环:分析对象 for (int c = 0; c < 6; c++) { //第二层循环:分析对象在时间点上的数据 String columnKey = "2001年" + (c + 1) + "月"; data.addValue(new Double(r * c + 5), rowKey, columnKey); }}JFreeChart chart = ChartFactory.createVerticalBarChart(title,domain,range,data,true,true,false);// then customise it a little...chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 1000, 0, Color.red));chart.setTitle(new TextTitle(title, new Font("隶书", Font.ITALIC, 15)));CategoryPlot plot = (CategoryPlot)chart.getPlot();plot.setForegroundAlpha(0.9f);plot.setValueLabelFont(new Font("黑体", Font.TRUETYPE_FONT, 12));//plot.setSectionLabelFont(new Font("黑体", Font.TRUETYPE_FONT, 12));//注意以下代码NumberAxis verticalAxis = (NumberAxis)plot.getRangeAxis();verticalAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());// 输出文件到指定目录String rfname = MathUtil.getRoundCode(22) + "b.jpeg";String fileName = "d:/test/" + rfname;try { ChartUtilities.saveChartAsJPEG(new File(fileName), 100, chart, 600, 600); // log.info("....Create image File:" + fileName);} catch (IOException exz) { System.out.print("....Cant’t Create image File");} //我编了一个静态的,看看效果怎么样//------------------------------------------------------------------------import java.awt.RenderingHints;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.Dimension;import java.awt.Container;import java.awt.BorderLayout;import java.awt.Color;import java.awt.geom.Arc2D;import java.awt.geom.Ellipse2D;import javax.swing.JFrame;import javax.swing.JPanel;public class DrawEllipse extends JFrame{ public DrawEllipse() { setTitle("柱形椭圆"); setSize(200,300); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); DrawPanel panel=new DrawPanel(); Container contentPane=getContentPane(); contentPane.add(panel,BorderLayout.CENTER); } public static void main(String[] args) { new DrawEllipse().show(); } class DrawPanel extends JPanel { public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2=(Graphics2D)g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Dimension szFrame=getSize(); Ellipse2D ellip=new Ellipse2D.Double(szFrame.getWidth()*0.05 ,szFrame.getHeight()*0.05,szFrame.getWidth()*0.9, szFrame.getHeight()*0.5); Arc2D arc=new Arc2D.Double(ellip.getBounds2D(),0,99,Arc2D.PIE); g2.setColor(Color.red); g2.fill(arc); g2.setColor(Color.yellow); g2.draw(arc); arc=new Arc2D.Double(ellip.getBounds2D(),99,141,Arc2D.PIE); g2.setColor(Color.blue); g2.fill(arc); g2.setColor(Color.yellow); g2.draw(arc); arc=new Arc2D.Double(ellip.getBounds2D(),240,120,Arc2D.PIE); g2.setColor(Color.green); g2.fill(arc); g2.setColor(Color.yellow); g2.draw(arc); for(int i=2;i<=10;i++) { Ellipse2D szPie=new Ellipse2D.Double(); szPie.setFrame(ellip.getX(), ellip.getY()+i,ellip.getWidth(),ellip.getHeight()); g2.setColor(Color.blue); arc=new Arc2D.Double(szPie.getBounds2D(),180,60,Arc2D.OPEN); g2.draw(arc); g2.setColor(Color.yellow); g2.draw(arc); g2.setColor(Color.green); arc=new Arc2D.Double(szPie.getBounds2D(),240,120,Arc2D.OPEN); g2.draw(arc); g2.setColor(Color.yellow); g2.draw(arc); } } }} Jfreechart我不知道这个是否支持jdk1.1.6版本的? to:yeahjava(梦魂) 上面的代码是我写的,实现不了上面提到的要求。 因为我只能用再浏览器中,所以只能用jdk1.1.6的,它没有这个类包,所以只能自己写类包,但没有算法!!!! import java.awt.RenderingHints;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.Dimension;import java.awt.Container;import java.awt.BorderLayout;import java.awt.Color;import java.awt.geom.Arc2D;import java.awt.geom.Ellipse2D;import javax.swing.JFrame;import javax.swing.JPanel;public class DrawEllipse extends JFrame{ public DrawEllipse() { setTitle("柱形椭圆"); setSize(400,550); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); DrawPanel panel=new DrawPanel(); Container contentPane=getContentPane(); contentPane.add(panel,BorderLayout.CENTER); } public static void main(String[] args) { new DrawEllipse().show(); } class DrawPanel extends JPanel { public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2=(Graphics2D)g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Dimension szFrame=getSize(); Ellipse2D ellip=new Ellipse2D.Double(szFrame.getWidth()*0.05 ,szFrame.getHeight()*0.05,szFrame.getWidth()*0.9, szFrame.getWidth()*0.9*0.4); Arc2D arc=new Arc2D.Double(ellip.getBounds2D(),0,99,Arc2D.PIE); g2.setColor(Color.red); g2.fill(arc); g2.setColor(Color.yellow); g2.draw(arc); arc=new Arc2D.Double(ellip.getBounds2D(),99,141,Arc2D.PIE); g2.setColor(Color.blue); g2.fill(arc); g2.setColor(Color.yellow); g2.draw(arc); arc=new Arc2D.Double(ellip.getBounds2D(),240,120,Arc2D.PIE); g2.setColor(Color.green); g2.fill(arc); g2.setColor(Color.yellow); g2.draw(arc); for(int i=2;i<=szFrame.getHeight()*0.5;i++) { Ellipse2D szPie=new Ellipse2D.Double(); szPie.setFrame(ellip.getX(), ellip.getY()+i,ellip.getWidth(),ellip.getHeight()); g2.setColor(Color.blue); arc=new Arc2D.Double(szPie.getBounds2D(),180,60,Arc2D.OPEN); g2.draw(arc); g2.setColor(Color.yellow); g2.draw(arc); g2.setColor(Color.green); arc=new Arc2D.Double(szPie.getBounds2D(),240,120,Arc2D.OPEN); g2.draw(arc); g2.setColor(Color.yellow); g2.draw(arc); } } }} 一个局域网的问题 String 使用NekoHTML过程中遇到的问题 祝大家新年快乐!散分! 初学者求助!,关于NullPointerException 错误, 求JDK1.4 API文档一份 求助一个关于JMF的问题。。。 快看阿! 为什么我的Jbuilder7.0没有中文字体? ie不支持java的swing类,sun说可以用plugin来扩充,而且不用客户的浏览棋手动安装,我用了java的plugin插件,不起作用,有用过的朋友多多指教? 刚学java,各位大哥、大姐、叔叔、阿姨能推荐几本书吗?? jb8+weblogic7配置很好,但是出现如下错误,请赐教
String domain = "单位比较";
String range = "数值";
//CategoryDataset data = DemoDatasetFactory.createCategoryDataset();
DefaultCategoryDataset data = new DefaultCategoryDataset();
for (int r = 0; r < 5; r++) {
String rowKey = "单位 [" + (r + 1)+"]" ;
//第一层循环:分析对象
for (int c = 0; c < 6; c++) {
//第二层循环:分析对象在时间点上的数据
String columnKey = "2001年" + (c + 1) + "月";
data.addValue(new Double(r * c + 5), rowKey, columnKey);
}
}JFreeChart chart = ChartFactory.createVerticalBarChart(title,domain,range,data,true,true,false);
// then customise it a little...
chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 1000, 0, Color.red));
chart.setTitle(new TextTitle(title, new Font("隶书", Font.ITALIC, 15)));
CategoryPlot plot = (CategoryPlot)chart.getPlot();
plot.setForegroundAlpha(0.9f);
plot.setValueLabelFont(new Font("黑体", Font.TRUETYPE_FONT, 12));
//plot.setSectionLabelFont(new Font("黑体", Font.TRUETYPE_FONT, 12));
//注意以下代码
NumberAxis verticalAxis = (NumberAxis)plot.getRangeAxis();
verticalAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
// 输出文件到指定目录
String rfname = MathUtil.getRoundCode(22) + "b.jpeg";
String fileName = "d:/test/" + rfname;
try {
ChartUtilities.saveChartAsJPEG(new File(fileName), 100, chart, 600, 600);
// log.info("....Create image File:" + fileName);
} catch (IOException exz) {
System.out.print("....Cant’t Create image File");
}
//------------------------------------------------------------------------import java.awt.RenderingHints;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Dimension;
import java.awt.Container;
import java.awt.BorderLayout;
import java.awt.Color;import java.awt.geom.Arc2D;
import java.awt.geom.Ellipse2D;
import javax.swing.JFrame;
import javax.swing.JPanel;public class DrawEllipse
extends JFrame
{ public DrawEllipse()
{
setTitle("柱形椭圆");
setSize(200,300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); DrawPanel panel=new DrawPanel(); Container contentPane=getContentPane();
contentPane.add(panel,BorderLayout.CENTER); } public static void main(String[] args)
{
new DrawEllipse().show();
} class DrawPanel
extends JPanel
{
public void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2=(Graphics2D)g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON); Dimension szFrame=getSize(); Ellipse2D ellip=new Ellipse2D.Double(szFrame.getWidth()*0.05
,szFrame.getHeight()*0.05,szFrame.getWidth()*0.9,
szFrame.getHeight()*0.5); Arc2D arc=new Arc2D.Double(ellip.getBounds2D(),0,99,Arc2D.PIE);
g2.setColor(Color.red);
g2.fill(arc);
g2.setColor(Color.yellow);
g2.draw(arc); arc=new Arc2D.Double(ellip.getBounds2D(),99,141,Arc2D.PIE); g2.setColor(Color.blue);
g2.fill(arc);
g2.setColor(Color.yellow);
g2.draw(arc); arc=new Arc2D.Double(ellip.getBounds2D(),240,120,Arc2D.PIE); g2.setColor(Color.green);
g2.fill(arc);
g2.setColor(Color.yellow);
g2.draw(arc); for(int i=2;i<=10;i++)
{ Ellipse2D szPie=new Ellipse2D.Double();
szPie.setFrame(ellip.getX(),
ellip.getY()+i,ellip.getWidth(),ellip.getHeight()); g2.setColor(Color.blue);
arc=new Arc2D.Double(szPie.getBounds2D(),180,60,Arc2D.OPEN);
g2.draw(arc);
g2.setColor(Color.yellow);
g2.draw(arc);
g2.setColor(Color.green);
arc=new Arc2D.Double(szPie.getBounds2D(),240,120,Arc2D.OPEN);
g2.draw(arc);
g2.setColor(Color.yellow);
g2.draw(arc); } }
}
}
上面的代码是我写的,实现不了上面提到的要求。
它没有这个类包,所以只能自己写类包,但没有算法!!!!
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Dimension;
import java.awt.Container;
import java.awt.BorderLayout;
import java.awt.Color;import java.awt.geom.Arc2D;
import java.awt.geom.Ellipse2D;
import javax.swing.JFrame;
import javax.swing.JPanel;public class DrawEllipse
extends JFrame
{ public DrawEllipse()
{
setTitle("柱形椭圆");
setSize(400,550);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); DrawPanel panel=new DrawPanel(); Container contentPane=getContentPane();
contentPane.add(panel,BorderLayout.CENTER); } public static void main(String[] args)
{
new DrawEllipse().show();
} class DrawPanel
extends JPanel
{
public void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2=(Graphics2D)g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON); Dimension szFrame=getSize(); Ellipse2D ellip=new Ellipse2D.Double(szFrame.getWidth()*0.05
,szFrame.getHeight()*0.05,szFrame.getWidth()*0.9,
szFrame.getWidth()*0.9*0.4); Arc2D arc=new Arc2D.Double(ellip.getBounds2D(),0,99,Arc2D.PIE);
g2.setColor(Color.red);
g2.fill(arc);
g2.setColor(Color.yellow);
g2.draw(arc); arc=new Arc2D.Double(ellip.getBounds2D(),99,141,Arc2D.PIE); g2.setColor(Color.blue);
g2.fill(arc);
g2.setColor(Color.yellow);
g2.draw(arc); arc=new Arc2D.Double(ellip.getBounds2D(),240,120,Arc2D.PIE); g2.setColor(Color.green);
g2.fill(arc);
g2.setColor(Color.yellow);
g2.draw(arc); for(int i=2;i<=szFrame.getHeight()*0.5;i++)
{ Ellipse2D szPie=new Ellipse2D.Double();
szPie.setFrame(ellip.getX(),
ellip.getY()+i,ellip.getWidth(),ellip.getHeight()); g2.setColor(Color.blue);
arc=new Arc2D.Double(szPie.getBounds2D(),180,60,Arc2D.OPEN);
g2.draw(arc);
g2.setColor(Color.yellow);
g2.draw(arc);
g2.setColor(Color.green);
arc=new Arc2D.Double(szPie.getBounds2D(),240,120,Arc2D.OPEN);
g2.draw(arc);
g2.setColor(Color.yellow);
g2.draw(arc); }
}
}
}