besthello

导航

jree-创建普通折线图

对于maven工程,需要引入依赖:
在pom.xml中,添加如下内容
<dependency>
<groupId>jfree</groupId>
<artifactId>jfreechart</artifactId>
<version>1.0.13</version>
</dependency>


  /**生成普通折线图
* @param imgTitle 图片的title
  * @param xLabel x轴标签
  * @param yLabel y轴标签
  /
1
public static void drawPNG(DefaultCategoryDataset ds, String savingPath, String imgTitle, String xLabel, String yLabel, int width, int height) { 2 JFreeChart lineChart = ChartFactory.createLineChart(imgTitle, xLabel, yLabel, ds, PlotOrientation.VERTICAL, true, true, false); 3 File chart = new File(savingPath); 4 try { 5 ChartUtilities.saveChartAsPNG(chart, lineChart, width, height); 6 } catch (Exception e) { 7 System.out.println(ErrorCodeEnum.CREATE_IMAGE_FAILED.getMessage()); 8 e.printStackTrace(); 9 } 10 11 }

  

  

 1 //创建数据集对象
 2    public static   DefaultCategoryDataset getDataSet(){   
 3         DefaultCategoryDataset line_chart_dataset = new DefaultCategoryDataset();
 4         line_chart_dataset.addValue(15, "schools", "1970");
 5         line_chart_dataset.addValue(30, "schools", "1980");
 6         line_chart_dataset.addValue(60, "schools", "1990");
 7         line_chart_dataset.addValue(120, "schools", "2000");
 8         line_chart_dataset.addValue(240, "schools", "2010");
 9         line_chart_dataset.addValue(300, "schools", "2014"); 
10         
11         return line_chart_dataset;
12 }

 

posted on 2019-05-20 20:21  besthello  阅读(309)  评论(0编辑  收藏  举报