JFreeChart开发股票K线图

 在JAVA的图形开发中,JFreeChart提供源代码及DEMO代码,详细的API工具,如果遇到问题还可以到http://www.jfree.org/phpBB2这个论坛一问究竟,全面的技术支持使图形开发起来得心应手!

下面的例子是用JFreeChart开发股票K线图,附有注释

 

import  java.sql. * ;
import  java.text.SimpleDateFormat;
import  java.util. * ;
import  java.lang. * ;
import  java.awt.Color;
import  java.awt.Font;

import  java.text.DecimalFormat;
import  java.text.SimpleDateFormat;
import  java.util.ArrayList;
import  java.util.Calendar;
import  java.util.Date;
import  java.util.HashMap;
import  java.util.Iterator;
import  java.util.List;
import  java.util.Map;

import  javax.swing.JApplet;
import  javax.swing.JPanel;

import  org.jfree.chart.ChartFrame;
import  org.jfree.chart.ChartPanel;
import  org.jfree.chart.JFreeChart;
import  org.jfree.chart.axis.DateAxis;
import  org.jfree.chart.axis.DateTickMarkPosition;
import  org.jfree.chart.axis.NumberTickUnit;
import  org.jfree.chart.axis.SegmentedTimeline;
import  org.jfree.chart.axis.DateTickUnit;
import  org.jfree.chart.axis.NumberAxis;
import  org.jfree.chart.block.BlockBorder;
import  org.jfree.chart.block.BlockContainer;
import  org.jfree.chart.block.BorderArrangement;
import  org.jfree.chart.labels.StandardXYToolTipGenerator;
import  org.jfree.chart.plot.CombinedDomainXYPlot;
import  org.jfree.chart.plot.Marker;
import  org.jfree.chart.plot.Plot;
import  org.jfree.chart.plot.XYPlot;
import  org.jfree.chart.renderer.xy.CandlestickRenderer;
import  org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import  org.jfree.chart.title.LegendTitle;
import  org.jfree.data.general.Dataset;
import  org.jfree.data.time.Day;
import  org.jfree.data.time.TimeSeries;
import  org.jfree.data.time.TimeSeriesCollection;
import  org.jfree.data.xy.DefaultHighLowDataset;
import  org.jfree.data.xy.IntervalXYDataset;
import  org.jfree.data.xy.OHLCDataset;
import  org.jfree.ui.HorizontalAlignment;
import  org.jfree.ui.RectangleEdge;

public   class  TestMinute  {
    
    List ls 
= new ArrayList();//定义一个用来保存数据的集合类List
    double max_vol,min_vol,max_pr,min_pr; 
    Date firstt,lastt;
    Map map 
= null;//用来表示一条记录

public void clearList(){ //清空保存数据的集合类List
        ls.clear();
 }

    
///该方法主要是为WEB端的JS调用,定义一个新的Map,插入一行空的记录
public void insertRecord() {
       map 
= new HashMap();
}


///该方法主要是为WEB端的JS调用,为当前记录设置值
public void setValue(java.lang.String string, java.lang.String value) {
       map.put(string, value);
}


///该方法主要是为WEB端的JS调用,把当前记录添加到记录集List里
public void postRecord() {
       ls.add(map);
}


public double[] calavergerprice(int datenum,double[] val){
     
int ini_num = val.length;
     
int size = ini_num-datenum+1;
     
double[] res = new double[size];
     
     
for(int i = 0;i<size;i++){
         
double tempval = 0.0
         
for(int j = i;j<(i+datenum);j++){
              tempval 
= tempval+val[j];
         }

          res[i] 
= tempval/datenum;
     }

     
return res;
}
    

//将数据库中数据读入ls集合中
public void readData(java.lang.String stock_id,int record_num){
    
try{
      Connection con 
= DatabaseConnection.getConection(); 
      Statement stmt 
= con.createStatement();
      ResultSet rs 
= stmt.executeQuery("select * from stockminute where stock_id = '"+stock_id+"' order by tran_time desc limit "+record_num);
      
double[] temp_avg = new double[record_num];
      
double[] vol_temp_avg = new double[record_num];
      
int index = 0;
      
int vol_index = 0;
      
while(rs.next()){
          temp_avg[index
++= rs.getDouble(7);
          vol_temp_avg[vol_index
++= rs.getDouble(8);
      }

      
//5,10,30日均价
      double[] avg5 = this.calavergerprice(5, temp_avg);
      
double[] avg10 = this.calavergerprice(10, temp_avg);
      
double[] avg30 = this.calavergerprice(30, temp_avg);
      
      
//5,10,30日均成交量
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值