package Time; import java.awt.Color; import java.awt.Font; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartFrame; import org.jfree.chart.JFreeChart; import org.jfree.chart.StandardChartTheme; import org.jfree.chart.plot.XYPlot; import org.jfree.data.time.Month; import org.jfree.data.time.TimeSeries; import org.jfree.data.time.TimeSeriesCollection; import org.jfree.ui.RectangleInsets; public class Time { public static void main(String[] args) { StandardChartTheme mTheme = new StandardChartTheme("CN"); mTheme.setExtraLargeFont(new Font("黑体", Font.BOLD, 20)); mTheme.setLargeFont(new Font("宋体", Font.BOLD, 20)); mTheme.setRegularFont(new Font("宋体", Font.BOLD, 20)); ChartFactory.setChartTheme(mTheme); TimeSeriesCollection mCollection = GetCollection(); JFreeChart mChart = ChartFactory.createTimeSeriesChart( "时间序列图", "年份", "数量", mCollection, true, true, false); mChart.setBackgroundPaint(Color.ORANGE); XYPlot mPlot = (XYPlot)mChart.getPlot(); mPlot.setBackgroundPaint(Color.lightGray); mPlot.setDomainGridlinePaint(Color.white); mPlot.setRangeGridlinePaint(Color.white); ChartFrame mChartFrame = new ChartFrame("时间序列图", mChart); mChartFrame.pack(); mChartFrame.setVisible(true); } public static TimeSeriesCollection GetCollection() { TimeSeriesCollection mCollection = new TimeSeriesCollection(); TimeSeries mSeiesFirst = new TimeSeries("First"); mSeiesFirst.add(new Month(1, 2012), 167.3D); mSeiesFirst.add(new Month(2, 2012), 181.8D);//这里用的是Month.class,同样还有Day.class Year.class 等等 mSeiesFirst.add(new Month(3, 2012), 167.3D); mSeiesFirst.add(new Month(4, 2012), 153.8D); mSeiesFirst.add(new Month(5, 2012), 167.6D); mSeiesFirst.add(new Month(6, 2012), 158.8D); mSeiesFirst.add(new Month(7, 2012), 148.3D); mSeiesFirst.add(new Month(8, 2012), 153.9D); mSeiesFirst.add(new Month(9, 2012), 142.7D); mSeiesFirst.add(new Month(10, 2012), 123.2D); mSeiesFirst.add(new Month(11, 2012), 131.8D); mSeiesFirst.add(new Month(12, 2012), 139.6D); mSeiesFirst.add(new Month(1, 2013), 142.9D); mSeiesFirst.add(new Month(2, 2013), 138.7D); mSeiesFirst.add(new Month(3, 2013), 137.3D); mSeiesFirst.add(new Month(4, 2013), 143.9D); mSeiesFirst.add(new Month(5, 2013), 139.8D); mSeiesFirst.add(new Month(6, 2013), 137D); mSeiesFirst.add(new Month(7, 2013), 132.8D); TimeSeries mSeiesSecond = new TimeSeries("Second"); mSeiesSecond.add(new Month(2, 2012), 129.6D); mSeiesSecond.add(new Month(3, 2012), 123.2D); mSeiesSecond.add(new Month(4, 2012), 117.2D); mSeiesSecond.add(new Month(5, 2012), 124.1D); mSeiesSecond.add(new Month(6, 2012), 122.6D); mSeiesSecond.add(new Month(7, 2012), 119.2D); mSeiesSecond.add(new Month(8, 2012), 116.5D); mSeiesSecond.add(new Month(9, 2012), 112.7D); mSeiesSecond.add(new Month(10, 2012), 101.5D); mSeiesSecond.add(new Month(11, 2012), 106.1D); mSeiesSecond.add(new Month(12, 2012), 110.3D); mSeiesSecond.add(new Month(1, 2013), 111.7D); mSeiesSecond.add(new Month(2, 2013), 111D); mSeiesSecond.add(new Month(3, 2013), 109.6D); mSeiesSecond.add(new Month(4, 2013), 113.2D); mSeiesSecond.add(new Month(5, 2013), 111.6D); mSeiesSecond.add(new Month(6, 2013), 108.8D); mSeiesSecond.add(new Month(7, 2013), 101.6D); mCollection.addSeries(mSeiesFirst); mCollection.addSeries(mSeiesSecond); return mCollection; } }
本文为xyw_Eliot原创,转载请注明出处:http://blog.csdn.net/xyw_eliot/article/details/8692700