欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

jfreechart设置字体

程序员文章站 2022-05-30 11:59:50
...

jfreechart设置字体

有中文的背景下,如果不设置字体,将会乱码。

分为柱状,饼状,曲线图。

分别为:

柱状:

TextTitle textTitle = chart.getTitle();
textTitle.setFont(new Font("黑体",Font.BOLD,15));

CategoryPlot plot=chart.getCategoryPlot();
CategoryAxis domainAxis=plot.getDomainAxis();
domainAxis.setLabelFont(new Font("黑体",Font.BOLD,15));
domainAxis.setTickLabelFont(new Font("黑体",Font.BOLD,15));
ValueAxis valueAxis=plot.getRangeAxis();
valueAxis.setLabelFont(new Font("黑体",Font.BOLD,15));


饼状:

	TextTitle textTitle = chart.getTitle();
	textTitle.setFont(new Font("黑体",Font.BOLD,15));
	
	PiePlot pieplot = (PiePlot) chart.getPlot();
	pieplot.setLabelFont(new Font("宋体", 0, 12));
	
	//没有数据的时候显示的内容 
	pieplot.setNoDataMessage("无数据显示");
	pieplot.setCircular(false);
	pieplot.setLabelGap(0.02D);
	
	chart.getLegend().setItemFont(new Font("黑体",Font.BOLD,15));

曲线:

	//设置子标题 
	TextTitle subtitle = new TextTitle("2007年度", new Font("黑体",
			Font.BOLD, 12));
	chart.addSubtitle(subtitle);
	//设置主标题 
	chart.setTitle(new TextTitle("阿蜜果blog访问量统计", new Font("隶书",
			Font.ITALIC, 15)));
	chart.setAntiAlias(true);
	
	XYPlot xyPlot=chart.getXYPlot();
	ValueAxis valueAxis=xyPlot.getDomainAxis();
	valueAxis.setLabelFont( new Font("黑体",
			Font.BOLD, 12));
	valueAxis.setTickLabelFont( new Font("黑体",
			Font.BOLD, 12));
	NumberAxis numberAxis = (NumberAxis) xyPlot.getRangeAxis();
	  // 设置y轴上的字体
    numberAxis.setTickLabelFont(new Font("宋体", Font.PLAIN, 13));
	 // 设置y轴上的标题字体
	numberAxis.setLabelFont(new Font("宋体", Font.PLAIN, 13));
    chart.getLegend().setItemFont(new Font("宋体", Font.PLAIN, 13));