效果图:
代码:
代码语言:javascript
复制
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();