- 使用JFreeChart 输出柱状图 基本参数设置:
使用JFreeChart 输出柱状图 基本参数设置:
- package com.*****************.domain.util;
-
- import java.awt.Color;
- import java.awt.Font;
- import java.text.DecimalFormat;
-
- import org.jfree.chart.JFreeChart;
- import org.jfree.chart.axis.CategoryAxis;
- import org.jfree.chart.axis.NumberAxis;
- import org.jfree.chart.axis.ValueAxis;
- import org.jfree.chart.labels.StandardCategoryItemLabelGenerator;
- import org.jfree.chart.plot.CategoryPlot;
- import org.jfree.chart.renderer.category.BarRenderer;
-
-
-
-
-
-
-
-
-
-
- public class FormatPic {
-
-
-
-
-
-
-
-
-
- public static void setView(JFreeChart chart){
-
- Font labelFont = new Font("SansSerif", Font.TRUETYPE_FONT, 12);
- Font noFont = new Font("SansSerif", Font.TRUETYPE_FONT, 48);
-
- CategoryPlot plot = chart.getCategoryPlot();
-
- plot.setNoDataMessage("没有数据!");
-
- plot.setNoDataMessageFont(noFont);
-
- plot.setNoDataMessagePaint(Color.RED);
-
- NumberAxis vn = (NumberAxis) plot.getRangeAxis();
-
- CategoryAxis domainAxis = plot.getDomainAxis();
-
-
- vn.setAutoRangeIncludesZero(true);
-
-
-
-
-
-
- domainAxis.setLabelFont(labelFont);
- domainAxis.setTickLabelFont(labelFont);
-
- ValueAxis rangeAxis = plot.getRangeAxis();
- rangeAxis.setLabelFont(labelFont);
- rangeAxis.setTickLabelFont(labelFont);
-
- BarRenderer renderer = new BarRenderer();
-
- renderer.setMaximumBarWidth(0.05);
-
-
-
- renderer.setBaseOutlinePaint(Color.BLACK);
-
- domainAxis.setLowerMargin(0.01);
-
-
-
-
-
-
-
- plot.setDomainAxis(domainAxis);
-
- plot.setBackgroundPaint(new Color(255, 255, 204));
-
-
- renderer.setItemMargin(0.05);
-
- renderer.setIncludeBaseInRange(true);
- renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
- renderer.setBaseItemLabelsVisible(true);
-
- plot.setRenderer(renderer);
- }
- }