JFreeChart插件完成的折線圖後果實例。本站提示廣大學習愛好者:(JFreeChart插件完成的折線圖後果實例)文章只能為提供參考,不一定能成為您想要的結果。以下是JFreeChart插件完成的折線圖後果實例正文
本文實例講述了JFreeChart插件完成的折線圖後果。分享給年夜家供年夜家參考,詳細以下:
package com.lei.jfreechart; import javax.swing.JPanel; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.plot.CategoryPlot; import org.jfree.chart.plot.PlotOrientation; import org.jfree.data.category.DefaultCategoryDataset; import org.jfree.ui.ApplicationFrame; import org.jfree.ui.RefineryUtilities; public class LineCharts extends ApplicationFrame { /** * */ private static final long serialVersionUID = 1L; public LineCharts(String s) { super(s); setContentPane(createDemoLine()); } public static void main(String[] args) { LineCharts fjc = new LineCharts("折線圖"); fjc.pack(); RefineryUtilities.centerFrameOnScreen(fjc); fjc.setVisible(true); } // 生成顯示圖表的面板 public static JPanel createDemoLine() { JFreeChart jfreechart = createChart(createDataset()); return new ChartPanel(jfreechart); } // 生成圖表主對象JFreeChart public static JFreeChart createChart(DefaultCategoryDataset linedataset) { // 界說圖表對象 JFreeChart chart = ChartFactory.createLineChart("一季度發賣曲線", //折線圖稱號 "時光", // 橫坐標稱號 "發賣額(百萬)", // 縱坐標稱號 linedataset, // 數據 PlotOrientation.VERTICAL, // 程度顯示圖象 true, // include legend true, // tooltips false // urls ); CategoryPlot plot = chart.getCategoryPlot(); plot.setRangeGridlinesVisible(true); //能否顯示格子線 plot.setBackgroundAlpha(0.3f); //設置配景通明度 NumberAxis rangeAxis = (NumberAxis)plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setAutoRangeIncludesZero(true); rangeAxis.setUpperMargin(0.20); rangeAxis.setLabelAngle(Math.PI / 2.0); return chart; } // 生成數據 public static DefaultCategoryDataset createDataset() { DefaultCategoryDataset linedataset = new DefaultCategoryDataset(); // 各曲線稱號 String series1 = "冰箱"; String series2 = "彩電"; String series3 = "洗衣機"; // 橫軸稱號(列稱號) String type1 = "1月"; String type2 = "2月"; String type3 = "3月"; linedataset.addValue(0.0, series1, type1); linedataset.addValue(4.2, series1, type2); linedataset.addValue(3.9, series1, type3); linedataset.addValue(1.0, series2, type1); linedataset.addValue(5.2, series2, type2); linedataset.addValue(7.9, series2, type3); linedataset.addValue(2.0, series3, type1); linedataset.addValue(9.2, series3, type2); linedataset.addValue(8.9, series3, type3); return linedataset; } }
運轉後果以下:
更多java相干內容感興致的讀者可檢查本站專題:《Java數據構造與算法教程》、《Java操作DOM節點技能總結》、《Java文件與目次操作技能匯總》和《Java緩存操作技能匯總》
願望本文所述對年夜家java法式設計有所贊助。