package com;
import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Paint;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.FieldPosition;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.StringTokenizer;
import javax.swing.*;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.LegendItem;
import org.jfree.chart.LegendItemCollection;
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.axis.DateTickMarkPosition;
import org.jfree.chart.axis.DateTickUnit;
import org.jfree.chart.axis.DateTickUnitType;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.SegmentedTimeline;
import org.jfree.chart.plot.CombinedDomainXYPlot;
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.XYBarRenderer;
import org.jfree.chart.renderer.xy.XYSplineRenderer;
import org.jfree.data.time.MovingAverage;
import org.jfree.data.xy.AbstractIntervalXYDataset;
import org.jfree.data.xy.DefaultOHLCDataset;
import org.jfree.data.xy.IntervalXYDataset;
import org.jfree.data.xy.OHLCDataItem;
import org.jfree.data.xy.OHLCDataset;
import org.jfree.data.xy.XYDataset;
public class CandlestickVolume {
static ChartPanel charPanel = null;
private static final Color COLOR_close = new Color(41, 36, 33);// 收盘价颜色 象牙黑
private static final Color COLOR_MA5 = new Color(138, 43, 226);// 5日均线颜色 紫
private static final Color COLOR_MA10 = new Color(30, 144, 255);// 10日均线颜色 蓝
private static final Color COLOR_MA15 = new Color(255, 165, 0);// 15日均线颜色
// 土黄
private static final Color COLOR_MA20 = new Color(255, 0, 255);// 20日均线颜色
// 深红
private static final Color COLOR_MA30 = new Color(240, 230, 140);// 30日均线颜色
// 黄褐
private static final Color COLOR_MA60 = new Color(0, 0, 128);// 60日均线颜色
// 藏青
private static final Color COLOR_MA120 = new Color(34, 193, 34);// 120日均线颜色
// 森林绿
private static final Color COLOR_MAVOL5 = new Color(138, 43, 226);// 5日均线颜色
// 金黄
private static final Color COLOR_MAVOL10 = new Color(255, 0, 0);// 10日均线颜色 红
private static int W_P = 3;// 价格宽度
private static int W_V = 1;// 成交量宽度
private static int WIDTH = 900;
private static int HEIGHT = 600;
private static int P_H = (int) (HEIGHT * (1.0 * W_P / (W_P + W_V)));// 价格高度
private static int V_H = (int) (HEIGHT * (1.0 * W_V / (W_P + W_V)));// 成交量高度
private static Color upColor = Color.RED.brighter();// 股票上涨的颜色 亮红色 收盘价大于开盘价
private static Color downColor = Color.GREEN.brighter();// 股票下跌的颜色 亮绿色
// 开盘价小于收盘价
public static void main(String[] args) {
JFreeChart chart = buildChart();// 建表
ChartFrame chartFrame = new ChartFrame("股票行情分析图", chart);
charPanel = chartFrame.getChartPanel();
// 创建菜单栏
JMenuBar mnb = new JMenuBar();
// 创建菜单
/* 1 */JMenu mnuSystem = new JMenu("系统(S)");
/* 2 */JMenu mnuSystem1 = new JMenu("工具(T)");
// 创建菜单项
JMenuItem mniCopy = new JMenuItem("复制");
mniCopy.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,InputEvent.CTRL_MASK));//设置快捷键Ctrl+C
mniCopy.addActionListener(new MyListener());
JMenuItem mniSaveas = new JMenuItem("另存为");
mniSaveas.addActionListener(new MyListener());
JMenuItem mniPrint = new JMenuItem("打印");
mniPrint.addActionListener(new MyListener());
JMenuItem mniEditChartProperties = new JMenuItem("属性");
mniEditChartProperties.addActionListener(new MyListener());
// 将菜单项添加到菜单中
mnuSystem.add(mniCopy);
mnuSystem.add(mniSaveas);
mnuSystem.addSeparator();
mnuSystem.add(mniPrint);
mnuSystem.addSeparator();
mnuSystem1.add(mniEditChartProperties );
// 将菜单添加到菜单栏中
/* 1 */mnb.add(mnuSystem);
/* 1 */mnb.add(mnuSystem1);
// 将菜单栏挂靠在框架上
chartFrame.setJMenuBar(mnb);
chartFrame.setSize(WIDTH, HEIGHT);// 设置尺寸
chartFrame.setVisible(true);// 设置为可见
}
public static JFreeChart buildChart() {
// X共用轴
DateAxis domainAxis = new DateAxis();// 设置区域轴(即为X轴) 也就是 时间轴
// 设置时间线显示的规则,用这个方法