import java.awt.Font; import java.awt.GridLayout; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import javax.swing.JFrame; 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.CategoryDataset; import org.jfree.data.category.DefaultCategoryDataset; import zxy.nlp.lda.conf.PathConfig; public class plotbetadis { ChartPanel frame1; public plotbetadis() throws IOException{ DefaultCategoryDataset dataset = (DefaultCategoryDataset) createDataset(); JFreeChart chart = ChartFactory.createLineChart("","date", "topic intensity/%",dataset,PlotOrientation.VERTICAL, true, true, true); CategoryPlot plot=chart.getCategoryPlot(); NumberAxis numberaxis = (NumberAxis)plot.getRangeAxis(); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); numberaxis.setLabelFont(new Font("黑体",Font.BOLD,14)); //水平底部标题 numberaxis.setTickLabelFont(new Font("宋体",Font.BOLD,12)); //垂直标题 frame1=new ChartPanel(chart,true); chart.getLegend().setItemFont(new Font("黑体", Font.BOLD, 15)); chart.getTitle().setFont(new Font("宋体",Font.BOLD,20));//设置标题字体 } private static CategoryDataset createDataset() throws IOException { DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset(); int lnum=2; String resPath = PathConfig.LdaResultsPath; String modelName = "ldatimes"; FileReader fr=new FileReader(filename); double[][] nodes = new double[lnum][]; String[] lines; //System.out.println("以行为单位读取文件内容,一次读一整行:"); BufferedReader br=new BufferedReader(fr); String line = null; int x=0; // 一次读入一行,直到读入null为文件结束 while ((line = br.readLine()) != null && x<lnum) { // 显示行号 //System.out.println("line " + lnum + ": " + line); lines = line.split("\t"); // for (int i = 0; i < lines.length; i++) { // System.out.println("一维 :" + lines[i] + " "); // } nodes[x] = new double[lines.length]; for (int y = 0; y < lines.length; y++) { nodes[x][y] = Double.parseDouble(lines[y]); String s = String.valueOf((y+4)/4); String t = String.valueOf(x); defaultcategorydataset.addValue(nodes[x][y], "top"+t, s); } x++; //lines = null; } br.close(); return defaultcategorydataset; } public ChartPanel getChartPanel(){ return frame1; } public static void main(String args[]) throws IOException{ JFrame frame=new JFrame("数据统计图"); frame.setLayout(new GridLayout(2,2,5,5)); frame.add(new plotbetadis().getChartPanel()); //添加折线图 frame.setBounds(50, 50, 600, 600); frame.setVisible(true); } }