Report Application Series-Chart Jfreechart: 2nd Chapter Column Chart

Source: Internet
Author: User

2.1. Simple Bar Chart

First prepare the data for the histogram, the histogram must use Categorydataset, here we use Defaultcategorydataset.

DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(100,"Spring Security","Jan");
dataset.addValue(200,"jBPM 4","Jan");
dataset.addValue(300,"Ext JS","Jan");
dataset.addValue(400,"JFreeChart","Jan");

Each call to AddValue () adds a piece of data to the dataset, which appears to be a columnar rectangle, the first parameter 100 is the length of the column rectangle, the second parameter represents the name of the data, and the third parameter represents the classification of the data.

With the chart data, the next step is to create a columnar chart with this data.

JFreeChart chart = ChartFactory.createBarChart(
   "chart",// 标题
   "num",// 横轴名称
   "type",// 纵轴名称
   dataset,// 数据
   PlotOrientation.VERTICAL,// 使用垂直柱状图
   true,// 是否使用legend 
   false,// 是否使用tooltip 
   false // 是否使用url链接
);

Finally, use Chartutilities to export chart as a PNG picture.

FileOutputStream fos = null;

try {
   fos = new FileOutputStream("target/bar1.png");
   ChartUtilities.writeChartAsPNG(fos,chart,400,300);
} finally {
   fos.close();
}

Figure 2.1. Simple bar Chart

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.