效果图:

Java通过GUI 做一个图书馆访问管理器-桃李博客

代码:


         Integer [][]visitordata={{2004,1500},{2005,1450},{2006,2000},{2007,2050},{2008,2500},{2009,2000},{2010,1600},{2011,3000},{2012,3200},
                                    {2013,4000},{2014,3500},{2015,2000},{2016,2300}};
        String []title={"年份","人数"};
        DefaultTableModel model = new DefaultTableModel();
        model.setDataVector(visitordata, title);
        tablevisitor.setModel(model);
        DefaultCategoryDataset chart_dataset = new DefaultCategoryDataset();
        for (int i = 0; i <= 12; i++) {
            chart_dataset.addValue(visitordata[i][1],"图书收集",visitordata[i][0]);
        }
        JFreeChart lineChart = ChartFactory.createLineChart("图书","年份", "访问量", chart_dataset, PlotOrientation.VERTICAL, true, true, false);
        ChartPanel chartpanel = new ChartPanel(lineChart);
        chartpanel.setSize(panelChart.getSize());
        panelChart.removeAll();
        panelChart.add(chartpanel);
        panelChart.validate();