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

📄 combinedxyplotdemo1.java

📁 jfreechart1.0.6源程序,没有注释,不过都能运行起来
💻 JAVA
📖 第 1 页 / 共 3 页
字号:




package demo;

import java.awt.*;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import javax.swing.JPanel;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.labels.StandardXYToolTipGenerator;
import org.jfree.chart.plot.CombinedDomainXYPlot;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.*;
import org.jfree.chart.title.LegendTitle;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.time.*;
import org.jfree.data.xy.IntervalXYDataset;
import org.jfree.data.xy.XYDataset;
import org.jfree.ui.*;

public class CombinedXYPlotDemo1 extends ApplicationFrame
{

    public CombinedXYPlotDemo1(String s)
    {
        super(s);
        JPanel jpanel = createDemoPanel();
        jpanel.setPreferredSize(new Dimension(500, 270));
        setContentPane(jpanel);
    }

    private static JFreeChart createCombinedChart()
    {
        IntervalXYDataset intervalxydataset = createDataset1();
        XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer(true, false);
        xylineandshaperenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0}: ({1}, {2})", new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00")));
        xylineandshaperenderer.setSeriesStroke(0, new BasicStroke(4F, 1, 2));
        xylineandshaperenderer.setSeriesPaint(0, Color.blue);
        DateAxis dateaxis = new DateAxis("Year");
        dateaxis.setLowerMargin(0.0D);
        dateaxis.setUpperMargin(0.02D);
        NumberAxis numberaxis = new NumberAxis("$billion");
        XYPlot xyplot = new XYPlot(intervalxydataset, null, numberaxis, xylineandshaperenderer);
        xyplot.setBackgroundPaint(Color.lightGray);
        xyplot.setDomainGridlinePaint(Color.white);
        xyplot.setRangeGridlinePaint(Color.white);
        IntervalXYDataset intervalxydataset1 = createDataset2();
        XYBarRenderer xybarrenderer = new XYBarRenderer() {

            public Paint getItemPaint(int i, int j)
            {
                XYDataset xydataset = getPlot().getDataset();
                if(xydataset.getYValue(i, j) >= 0.0D)
                    return Color.red;
                else
                    return Color.green;
            }

        }
;
        xybarrenderer.setSeriesPaint(0, Color.red);
        xybarrenderer.setDrawBarOutline(false);
        xybarrenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0}: ({1}, {2})", new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00")));
        XYPlot xyplot1 = new XYPlot(intervalxydataset1, null, new NumberAxis("$billion"), xybarrenderer);
        xyplot1.setBackgroundPaint(Color.lightGray);
        xyplot1.setDomainGridlinePaint(Color.white);
        xyplot1.setRangeGridlinePaint(Color.white);
        CombinedDomainXYPlot combineddomainxyplot = new CombinedDomainXYPlot(dateaxis);
        combineddomainxyplot.add(xyplot, 3);
        combineddomainxyplot.add(xyplot1, 2);
        combineddomainxyplot.setGap(8D);
        combineddomainxyplot.setDomainGridlinePaint(Color.white);
        combineddomainxyplot.setDomainGridlinesVisible(true);
        JFreeChart jfreechart = new JFreeChart("United States Public Debt", JFreeChart.DEFAULT_TITLE_FONT, combineddomainxyplot, false);
        jfreechart.setBackgroundPaint(Color.white);
        TextTitle texttitle = new TextTitle("Source: http://www.publicdebt.treas.gov/opd/opdhisms.htm", new Font("Dialog", 0, 10));
        texttitle.setPosition(RectangleEdge.BOTTOM);
        texttitle.setHorizontalAlignment(HorizontalAlignment.RIGHT);
        jfreechart.addSubtitle(texttitle);
        LegendTitle legendtitle = new LegendTitle(combineddomainxyplot);
        jfreechart.addSubtitle(legendtitle);
        return jfreechart;
    }

    private static IntervalXYDataset createDataset1()
    {
        TimeSeries timeseries = new TimeSeries("Public Debt Outstanding", org.jfree.data.time.Month.class);
        timeseries.add(new Month(1, 1990), 2974.5839999999998D);
        timeseries.add(new Month(2, 1990), 2994.3539999999998D);
        timeseries.add(new Month(3, 1990), 3051.9560000000001D);
        timeseries.add(new Month(4, 1990), 3061.0129999999999D);
        timeseries.add(new Month(5, 1990), 3095.172D);
        timeseries.add(new Month(6, 1990), 3143.7539999999999D);
        timeseries.add(new Month(7, 1990), 3168.7719999999999D);
        timeseries.add(new Month(8, 1990), 3211.6909999999998D);
        timeseries.add(new Month(9, 1990), 3233.3130000000001D);
        timeseries.add(new Month(10, 1990), 3274.9499999999998D);
        timeseries.add(new Month(11, 1990), 3330.6849999999999D);
        timeseries.add(new Month(12, 1990), 3364.8200000000002D);
        timeseries.add(new Month(1, 1991), 3411.4090000000001D);
        timeseries.add(new Month(2, 1991), 3458.6370000000002D);
        timeseries.add(new Month(3, 1991), 3441.3670000000002D);
        timeseries.add(new Month(4, 1991), 3445.0590000000002D);
        timeseries.add(new Month(5, 1991), 3497.232D);
        timeseries.add(new Month(6, 1991), 3537.9879999999998D);
        timeseries.add(new Month(7, 1991), 3576.8270000000002D);
        timeseries.add(new Month(8, 1991), 3614.3989999999999D);
        timeseries.add(new Month(9, 1991), 3665.3029999999999D);
        timeseries.add(new Month(10, 1991), 3717.1060000000002D);
        timeseries.add(new Month(11, 1991), 3747.3629999999998D);
        timeseries.add(new Month(12, 1991), 3801.6979999999999D);
        timeseries.add(new Month(1, 1992), 3809.3339999999998D);
        timeseries.add(new Month(2, 1992), 3829.0590000000002D);
        timeseries.add(new Month(3, 1992), 3881.288D);
        timeseries.add(new Month(4, 1992), 3891.9740000000002D);
        timeseries.add(new Month(5, 1992), 3934.4349999999999D);
        timeseries.add(new Month(6, 1992), 3984.6559999999999D);
        timeseries.add(new Month(7, 1992), 4010.6120000000001D);
        timeseries.add(new Month(8, 1992), 4048.9380000000001D);
        timeseries.add(new Month(9, 1992), 4064.6210000000001D);
        timeseries.add(new Month(10, 1992), 4067.3290000000002D);
        timeseries.add(new Month(11, 1992), 4132.5249999999996D);
        timeseries.add(new Month(12, 1992), 4177.009D);
        timeseries.add(new Month(1, 1993), 4167.1999999999998D);
        timeseries.add(new Month(2, 1993), 4197.0039999999999D);
        timeseries.add(new Month(3, 1993), 4230.5799999999999D);
        timeseries.add(new Month(4, 1993), 4254.0839999999998D);
        timeseries.add(new Month(5, 1993), 4296.2780000000002D);
        timeseries.add(new Month(6, 1993), 4351.9499999999998D);
        timeseries.add(new Month(7, 1993), 4350.2610000000004D);
        timeseries.add(new Month(8, 1993), 4403.3130000000001D);
        timeseries.add(new Month(9, 1993), 4411.4889999999996D);
        timeseries.add(new Month(10, 1993), 4422.5110000000004D);
        timeseries.add(new Month(11, 1993), 4493.5349999999999D);
        timeseries.add(new Month(12, 1993), 4535.6869999999999D);
        timeseries.add(new Month(1, 1994), 4526.308D);
        timeseries.add(new Month(2, 1994), 4559.5410000000002D);
        timeseries.add(new Month(3, 1994), 4575.8689999999997D);
        timeseries.add(new Month(4, 1994), 4568.7039999999997D);
        timeseries.add(new Month(5, 1994), 4609.2960000000003D);
        timeseries.add(new Month(6, 1994), 4645.8019999999997D);
        timeseries.add(new Month(7, 1994), 4636.3620000000001D);
        timeseries.add(new Month(8, 1994), 4691.991D);
        timeseries.add(new Month(9, 1994), 4692.75D);
        timeseries.add(new Month(10, 1994), 4734.1670000000004D);
        timeseries.add(new Month(11, 1994), 4778.5200000000004D);
        timeseries.add(new Month(12, 1994), 4800.1499999999996D);
        timeseries.add(new Month(1, 1995), 4815.8270000000002D);
        timeseries.add(new Month(2, 1995), 4854.2979999999998D);
        timeseries.add(new Month(3, 1995), 4864.116D);
        timeseries.add(new Month(4, 1995), 4852.3270000000002D);
        timeseries.add(new Month(5, 1995), 4903.9260000000004D);
        timeseries.add(new Month(6, 1995), 4951.3720000000003D);
        timeseries.add(new Month(7, 1995), 4960.152D);
        timeseries.add(new Month(8, 1995), 4970.7560000000003D);
        timeseries.add(new Month(9, 1995), 4973.9830000000002D);
        timeseries.add(new Month(10, 1995), 4985.2619999999997D);
        timeseries.add(new Month(11, 1995), 4989.3299999999999D);
        timeseries.add(new Month(12, 1995), 4988.665D);
        timeseries.add(new Month(1, 1996), 4987.4359999999997D);
        timeseries.add(new Month(2, 1996), 5017.0410000000002D);
        timeseries.add(new Month(3, 1996), 5117.7860000000001D);
        timeseries.add(new Month(4, 1996), 5102.049D);
        timeseries.add(new Month(5, 1996), 5128.509D);
        timeseries.add(new Month(6, 1996), 5161.076D);
        timeseries.add(new Month(7, 1996), 5188.8890000000001D);
        timeseries.add(new Month(8, 1996), 5208.3029999999999D);
        timeseries.add(new Month(9, 1996), 5224.8109999999997D);
        timeseries.add(new Month(10, 1996), 5247.3199999999997D);
        timeseries.add(new Month(11, 1996), 5296.549D);
        timeseries.add(new Month(12, 1996), 5323.1719999999996D);

⌨️ 快捷键说明

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