⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 drawgraphpro.java0

📁 一个画股票曲线并发送邮件的程序。 采用freechart和javamail技术。
💻 JAVA0
字号:
package com.shfe.mail;

import java.awt.*;
import javax.swing.JPanel;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
import java.util.*;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.*;
import org.jfree.chart.renderer.xy.*;
import org.jfree.chart.axis.*;
import org.jfree.data.Range;
import org.jfree.data.xy.*;
import com.shfe.mail.*;
import java.text.*;
import java.io.*;
import org.jfree.chart.*;
import org.jfree.chart.renderer.xy.XYBarRenderer.*;
import org.jfree.chart.title.*;
import org.jfree.ui.*;

public class DrawGraphPro extends ApplicationFrame {
    static FuturesMap fmap = FuturesMap.getInstance();
    public DrawGraphPro(String s) {
        super(s);
        JFreeChart jfreechart = createChart();
        ChartPanel chartpanel = new ChartPanel(jfreechart);
        chartpanel.setPreferredSize(new Dimension(550, 340));
        setContentPane(chartpanel);
    }

    private static JFreeChart createChart() {

        Map resultMap = fmap.getFuturesData();
        ScaleBean scale = (ScaleBean) resultMap.get("scale");
        double maxPrice = scale.getMaxPrice();
        double minPrice = scale.getMinPrice();
        double plinePriceLength = maxPrice - minPrice;
        double maxAmount = scale.getMaxAmount();
        double closePrice = scale.getClosePrice();

        //Pline
        XYDataset xyPlinedataset = createPLineDataset();
        StandardXYItemRenderer sxyrender = new StandardXYItemRenderer();
        sxyrender.setPaint(Color.BLUE);
        NumberAxis plineAxisLeft = new NumberAxis();
        plineAxisLeft.setRange(new Range(minPrice, maxPrice));
        NumberTickUnit plineTick=new NumberTickUnit(plinePriceLength / 10);
        plineAxisLeft.setTickUnit(plineTick);
        DecimalFormat decimalformat = new DecimalFormat("#0.00");
        plineAxisLeft.setNumberFormatOverride(decimalformat);
        plineAxisLeft.setTickLabelPaint(Color.red);
        plineAxisLeft.setTickMarksVisible(false);

        // pline percent
        NumberAxis plineAxisRight = new NumberAxis();
        plineAxisRight.setRange((minPrice-closePrice)/closePrice,(maxPrice-closePrice)/closePrice);
        NumberTickUnit plinePercentTick=new NumberTickUnit(plinePriceLength/(closePrice*10));
        plineAxisRight.setTickUnit(plinePercentTick);
        DecimalFormat numberformatRight = new DecimalFormat("#0.00%");
        plineAxisRight.setNumberFormatOverride(numberformatRight);
        plineAxisRight.setTickLabelPaint(Color.red);

        XYPlot plinePlot = new XYPlot();//xyPlinedataset, null, plineAxis,sxyrender);
        plinePlot.setRenderer(sxyrender);
        plinePlot.setDataset(xyPlinedataset);
        plinePlot.setRangeAxis(0, plineAxisLeft);
        plinePlot.setRangeAxis(1, plineAxisRight);

        //Amount
        IntervalXYDataset xyAmountdataset = createAmountDataset();
        XYBarRenderer xybarRender = new XYBarRenderer();
        xybarRender.setPaint(Color.BLUE);
        NumberAxis amountYAxis = new NumberAxis();
        amountYAxis.setRange(0, maxAmount);

        amountYAxis.setTickUnit(new NumberTickUnit(maxAmount / 5));
        DecimalFormat numberformat = new DecimalFormat("#0");
        amountYAxis.setNumberFormatOverride(numberformat);
        XYPlot amountPlot = new XYPlot(xyAmountdataset, null, amountYAxis, xybarRender);

        //combine
	NumberAxis domainAxis = new NumberAxis();
        domainAxis.setTickUnit(new NumberTickUnit(3600));
        domainAxis.setTickLabelsVisible(false);
        domainAxis.setLowerMargin(0D);
        domainAxis.setUpperMargin(0D);
        CombinedDomainXYPlot combinePlot = new CombinedDomainXYPlot(domainAxis);
        combinePlot.setOrientation(PlotOrientation.VERTICAL);
        combinePlot.add(plinePlot,2);
        combinePlot.add(amountPlot,1);

	JFreeChart jfreechart=new JFreeChart("IF0508", JFreeChart.DEFAULT_TITLE_FONT, combinePlot, false);
        jfreechart.setBackgroundPaint(Color.white);
        TextTitle domainTick = new TextTitle("9:15                                                                11:30/13:00                                                           15:15");
        domainTick.setFont(new Font("SansSerif", 0, 10));
        domainTick.setPosition(RectangleEdge.BOTTOM);
        domainTick.setHorizontalAlignment(HorizontalAlignment.CENTER);
        jfreechart.addSubtitle(domainTick);

        return jfreechart;
    }

    private static XYDataset createPLineDataset() {
        //x,y
        Map resultMap = fmap.getFuturesData();
        java.util.List points = (java.util.List) resultMap.get("points");
        XYSeries xyseries = new XYSeries("Series 1");
        for (int i = 0; i < points.size(); i++) {
            PointBean point = (PointBean) points.get(i);
            double xPoint = point.getPointTime();
            double yPoint = point.getPointPrice();
            //if(i<10)System.out.println("xPoint0="+xPoint+"yPoint0="+yPoint);
            xyseries.add(xPoint, yPoint);
        }
        return new XYSeriesCollection(xyseries);
    }

    private static IntervalXYDataset createAmountDataset() {
        //x,y
        Map resultMap = fmap.getFuturesData();
        java.util.List points = (java.util.List) resultMap.get("points");
        XYSeries xyseries = new XYSeries("Series 2");
        for (int i = 0; i < points.size(); i++) {
            PointBean point = (PointBean) points.get(i);
            double xPoint = point.getPointTime();
            double yPoint = point.getPointAmount();
            //if(i<10)System.out.println("xPoint1="+xPoint+"yPoint1="+yPoint);
            xyseries.add(xPoint, yPoint);
        }
        XYSeriesCollection xyseriescollection = new XYSeriesCollection();
        xyseriescollection.addSeries(xyseries);
        return new XYBarDataset(xyseriescollection, 0.00000000000000002D);
        //return new XYSeriesCollection(xyseries);
    }

    public static void main(String args[]) {
        DrawGraphPro xyseriesdemo1 = new DrawGraphPro("IF0508");
        xyseriesdemo1.pack();
        RefineryUtilities.centerFrameOnScreen(xyseriesdemo1);
        xyseriesdemo1.setVisible(true);
        FileOutputStream fos_jpg = null;
        try {
            fos_jpg = new FileOutputStream("C:\\Furtures.jpg");
            ChartUtilities.writeChartAsJPEG(fos_jpg, 100,xyseriesdemo1.createChart(), 550,340, null);
        } catch (Exception ex) {
        } finally {
            try {
                fos_jpg.close();
            } catch (Exception e) {}
        }

    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -