Java drawing icon (pie chart) JFreeChart quickly create a chart through Java

JFreeChart

JFreeChart is an open chart drawing library on the JAVA platform. It is completely written in JAVA language and is designed for applications, applets, servlets and JSP. JFreeChart can generate pie charts, bar charts, scatter plots, time series, Gantt charts, etc., and can generate PNG and The output of JPEG format can also be associated with PDF and EXCEL.
Getting started demo
generates a pie chart picture chart.png
in the root directory of Disk D, and generates a pie chart picture chart.png in the root directory of Disk D

1) Create JfreeChartDemo project, create Maven progect

Insert picture description here

2) Introduce related jar packages

Insert picture description here
Insert picture description here

3) Create a class

Insert picture description here

4) Create the main method in JFreeCharDemo and create the DefaultPieDataset object, and set the corresponding value to the object
package com.itzheng.demo;
import java.io.File;
import java.io.IOException;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.data.general.DefaultPieDataset;
public class JFreeCharDemo {
    
    
	public static void main(String[] args) throws IOException {
    
    
		DefaultPieDataset dataSet = new DefaultPieDataset();
		//设置数据集
		dataSet.setValue("家电", 10086);
		dataSet.setValue("百货", 9527);
		dataSet	.setValue("食品", 110110);
		//参数1:title = 图标的标题
		//参数2:PieDataset = 数据集(这里是dataSet)
		//参数3:true = 设置是否显示下标题(legend)
		//参数4:toopltip:鼠标移动过去的提示
		//参数5:url是否为超链接
		JFreeChart chart =  ChartFactory.createPieChart("标题",dataSet,true,false,false);
		//保存到本地目录下
		//参数1:文件名称,本地的目录
		//参数2:图标对象
		//参数3:图标的宽度
		//参数4:图标的高度
		ChartUtilities.saveChartAsPNG(new File("d:\\pie.png"), chart, 500, 500);
		
	}
}
5) Run the appeal procedure

Insert picture description here
Chart created successfully
Insert picture description here

Guess you like

Origin blog.csdn.net/qq_44757034/article/details/109963149