首 页文章中心下载中心繁體中文
设为首页
加入收藏
联系我们
您当前的位置:开源盛世-源代码下载网 -> 文章中心 -> 其他编程 -> Java技术 -> 文章内容 退出登录 用户管理
栏目导航
· VC# 技术 · Delphi技术
· Java技术 · 通用算法
· 编程相关
热门文章
· Tab Control控件使用...
· 学生档案管理系统
· [图文] 排列组合公式
· UTF-8与GB2312之间的...
· DirectShow下载安装...
· Virtual PC 在PAE模...
· Windows2000终端服务...
· MapInfo上的GIS系统...
· Mapbasic参考手册索...
· MapX应用开发中文讲...
相关文章
· 在Java中向Excel文件...
· 在Java中读取Excel文...
在Java中使用Oracle Chart Builder输出图表
作者:佚名  来源:vscodes.com整理  发布时间:2005-12-16 12:59:37  发布人:Polaris

减小字体 增大字体

可随意转载,但请注明出处及作者
SonyMusic
2003.05.15
==========================================================================
在Java中使用Oracle Chart Builder输出图表


package test.chart;

import java.awt.Color;
import java.awt.Font;
import java.awt.Frame;
import java.awt.Graphics2D;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;

import oracle.charts.axischart.AxisChart;
import oracle.charts.types.AnnotationDesc;
import oracle.charts.types.ChartException;
import oracle.charts.types.LineDesc;
import oracle.charts.types.BarDesc;
import oracle.charts.types.MarkerDesc;
import oracle.charts.types.NumAxisDesc;

/**
* @author SonyMusic
*
* 简单的测试了Oracle Chart的用法.
* 下载地址:http://otn.oracle.com/software/tech/java/servlets/content.html
*/
public class TestChart1 {

    //月份,其实就是X轴的标尺内容
    public final static String annualDates[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" };

    //这是实际数据
    public final static double p2002[] = { 1768, 1891, 1707, 1630, 1678, 1761 };
    public final static double p2001[] = { 1697, 1787, 1684, 1870, 1847, 1852, 1858, 1901, 2016, 2068, 1863, 1891 };

    public static void main(String[] args) {

        // 嵌入图表的窗口(frame)的高和宽
        int chartHeight = 400;
        int chartWidth = 600;

        Frame f = new Frame();
        f.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                e.getWindow().dispose();
            }
        });
        f.setSize(chartWidth + 10, chartHeight + 40);
        f.setTitle("Oracle Chart测试窗口");

        try {

            // 创建AxisChart对象
            AxisChart axisCh = new AxisChart();

            //
            // 图表的高和宽
            axisCh.setSize(chartWidth, chartHeight);

            //
            // 将时间戳放入X轴
            axisCh.setXSeries(annualDates);

            //
            // 将价格数字插入到Y轴,并有对应的名称
            String y2001 = "2001年";
            String y2002 = "2002年";
            axisCh.setYSeries(y2001, p2001);
            axisCh.setYSeries(y2002, p2002);

            //
            // 定义Line类型的图表,并设置线条颜色宽度,标记的类型和颜色
            //还可以定义其它类型,如:BarDesc
            LineDesc ld2001 = new LineDesc();
            ld2001.setLineColor(Color.RED);
            ld2001.setMarkerType(MarkerDesc.MARKER_CIRCLE);
            ld2001.setLineWidth(1);
            ld2001.setMarkerColor(Color.GREEN);

            LineDesc ld2002 = new LineDesc();
            ld2002.setLineColor(Color.BLUE);
            ld2002.setMarkerType(MarkerDesc.MARKER_DIAMOND);
            ld2002.setLineWidth(1);
            ld2002.setMarkerColor(Color.BLACK);

            //将两个线加到图表中去,并与名称对应上
            axisCh.setSeriesGraphic(y2001, ld2001);
            axisCh.setSeriesGraphic(y2002, ld2002);

            //设置图表的背景色
            AnnotationDesc ad = axisCh.getAnnotationDesc();
            ad.setForeground(Color.CYAN);

            //设置图表Y轴标尺的颜色、间隔,以及范围
            NumAxisDesc nad = new NumAxisDesc();
            nad.setColor(Color.black);
            nad.setLabelIncrement(100);
            nad.setExtent(1200, 2500);

            axisCh.setChartAttributes(nad);

            //
            // 设置标题, 子标题, 和脚注. 及其字体
            axisCh.getTitle().setText("2002年与2001年同期现款价格比较");
            axisCh.getTitle().setFont(new Font("宋体", Font.PLAIN, 18));
            axisCh.getSubtitle().setText("钢坯(单价:元/吨)");
            axisCh.getFootnote().setText("数据来源:销售科             时间(月)");

            //
            // 将图表添加到窗口中
            f.add(axisCh);

            //还可以输出到一个OutputStream中--以下的out
            //以下用到了Acme中的Gif Encode组件
            /*
            BufferedImage image = new BufferedImage(chartWidth, chartHeight,
                                                    BufferedImage.TYPE_INT_RGB);
            Graphics2D g = (Graphics2D) image.getGraphics();
            axisCh.drawBuffer(g);

            GifEncoder ge = new GifEncoder(image, out);
            ge.encode();
            */

        }
        catch (ChartException e) {
            System.out.println(e.getMessage());
        }

        f.show();

    }
}

End of《在Java中使用Oracle Chart Builder输出图表》

[] [返回上一页] [打 印] [收 藏]
 
∷相关“在Java中使用Oracle Chart Builder输出图表”文章评论∷
(评论内容只代表网友观点,与本站立场无关!) [更多评论...]
关于本站 - 网站帮助 - 广告合作 - 下载声明 - 友情连接 - 网站地图 网站目录 鄂ICP备06007162
开源盛世 版权所有Copyright © 2003-2005 VSCodes.Com. All Rights Reserved.