ssh中配置JFreeChart

阅读更多
前提:struts2,spring3.0.5配置完毕

下面配置JFreeChart:
需要导入的jar(可从附件下载):
jcommon-1.0.17.jar
jfreechart-1.0.14.jar
struts2-jfreechart-plugin-2.2.3.jar

struts-config.xml
---------------------




	
		
			
				500
				370
			
		
		
	



Action
----------------------
public class ChartAction extends ActionSupport {


	public String execute() {
	
		// 暂时使用null
		getChart1(null, null);
	
		return "success";
	}

	
	public JFreeChart getChart1(TbChannelInfo ch, List dyDataList) {
		log.debug(className + " getChart1 start");

		// 有序排序
		chart = null;
		chart = ChartFactory.createTimeSeriesChart("Dynamic Trend Graphical.", "时间", "mv",
				getDataSet(), false, false, false);
		
		// 重新设置图标标题,改变字体
		chart.setTitle(new TextTitle("Dynamic Trend Graphical.", new Font("黑体", Font.ITALIC, 22)));
		
		
		// 取得统计图标的第一个图例
		//LegendTitle legend = chart.getLegend();
		
		// 修改图例的字体
		//legend.setItemFont(new Font("宋体", Font.BOLD, 14));

		XYPlot plot = (XYPlot) chart.getPlot();
		
		// 取得横轴
		ValueAxis categoryAxis = plot.getDomainAxis();
		
		// 设置横轴显示标签的字体
		categoryAxis.setLabelFont(new Font("宋体", Font.BOLD, 22));
		categoryAxis.setTickLabelFont(new Font("宋体", Font.BOLD, 18));
		
		// 取得纵轴
		NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis();
		
		// 设置纵轴显示标签的字体
		numberAxis.setLabelFont(new Font("宋体", Font.BOLD, 22));
		
		return chart;

	}

	private XYDataset getDataSet() {
		TimeSeries apple = new TimeSeries("测点一", Month.class);
		apple.add(new Month(10, 2007), 3900);
		apple.add(new Month(11, 2007), 900);
		apple.add(new Month(12, 2007), 2500);
		apple.add(new Month(1, 2008), 3900);
		apple.add(new Month(2, 2008), 2000);
		apple.add(new Month(3, 2008), 3300);

		TimeSeries orange = new TimeSeries("测点二", Month.class);
		orange.add(new Month(10, 2007), 3300);
		orange.add(new Month(11, 2007), 2680);
		orange.add(new Month(12, 2007), 2000);
		orange.add(new Month(1, 2008), 1900);
		orange.add(new Month(2, 2008), 2000);
		orange.add(new Month(3, 2008), 2300);

		TimeSeriesCollection dataset = new TimeSeriesCollection();
		dataset.addSeries(apple);
		dataset.addSeries(orange);
		return dataset;
	}


}




JSP
------------------

  • struts2-jfreechart-plugin-2.2.3.jar.zip (13.5 KB)
  • 下载次数: 75
  • jfreechart-1.0.14.zip (7.5 MB)
  • 下载次数: 47

你可能感兴趣的:(jfreechart,ssh,struts,spring)