`

jfreechar 柱状图

阅读更多

版本: jfreechar.1.0.13









package demo;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Paint;
import java.awt.PaintContext;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.Stroke;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import java.awt.image.ColorModel;

import javax.swing.JPanel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.labels.StandardCategoryItemLabelGenerator;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.CategoryItemRenderer;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
import org.jfree.util.PaintList;

public class BarChartDemo8 extends ApplicationFrame
{
  public BarChartDemo8(String paramString)
  {
    super(paramString);
    CategoryDataset localCategoryDataset = createDataset();
    JFreeChart localJFreeChart = createChart(localCategoryDataset);
    ChartPanel localChartPanel = new ChartPanel(localJFreeChart);
    localChartPanel.setPreferredSize(new Dimension(500, 270));
    setContentPane(localChartPanel);
  }

  private static CategoryDataset createDataset()
  {
    String str1 = "First";
    String str2 = "Second";
    String str3 = "Third";
    String str4 = "北京";
    String str5 = "天津";
    String str6 = "上海";
    String str7 = "广州";
    String str8 = "深圳";
    
    
    
    
    DefaultCategoryDataset localDefaultCategoryDataset = new DefaultCategoryDataset();
    localDefaultCategoryDataset.addValue(1.0D, str1, str4);
    localDefaultCategoryDataset.addValue(4.0D, str1, str5);
    localDefaultCategoryDataset.addValue(3.0D, str1, str6);
    localDefaultCategoryDataset.addValue(5.0D, str1, str7);
    localDefaultCategoryDataset.addValue(5.0D, str1, str8);
    
    
  
    
    /*localDefaultCategoryDataset.addValue(5.0D, str2, str4);
    localDefaultCategoryDataset.addValue(7.0D, str2, str5);
    localDefaultCategoryDataset.addValue(6.0D, str2, str6);
    localDefaultCategoryDataset.addValue(8.0D, str2, str7);
    localDefaultCategoryDataset.addValue(4.0D, str2, str8);
    
    localDefaultCategoryDataset.addValue(4.0D, str3, str4);
    localDefaultCategoryDataset.addValue(3.0D, str3, str5);
    localDefaultCategoryDataset.addValue(2.0D, str3, str6);
    localDefaultCategoryDataset.addValue(3.0D, str3, str7);
    localDefaultCategoryDataset.addValue(6.0D, str3, str8);
    */
    
    return localDefaultCategoryDataset;
  }

  private static JFreeChart createChart(CategoryDataset paramCategoryDataset)
  {
      
      Font font = new Font("微软雅黑", Font.PLAIN, 12);  
      
      Font fontTitle = new Font("微软雅黑", Font.BOLD, 14);  
      
      
    /**
     * Creates a bar chart. The chart object returned by this method uses a 
     * CategoryPlot instance as the plot, with a CategoryAxis for the domain axis, 
     * a NumberAxis as the range axis, and a BarRenderer as the renderer.

        Parameters:
                    title : the chart title (null permitted).
                    categoryAxisLabel : the label for the category axis (null permitted).
                    valueAxisLabel : the label for the value axis (null permitted).
                    dataset : the dataset for the chart (null permitted).
                    orientation : the plot orientation (horizontal or vertical) (null not permitted).
                    legend : a flag specifying whether or not a legend is required.
                    tooltips : configure chart to generate tool tips?
                    urls : configure chart to generate URLs?
        Returns:
                    A bar chart.  
     */
    JFreeChart localJFreeChart = 
        ChartFactory.createBarChart("注册会员统计", 
                                    "( 月份 )", 
                                    "数量", 
                                    paramCategoryDataset, 
                                    PlotOrientation.VERTICAL,
                                    false, 
                                    true, 
                                    false);
    
    
    //localJFreeChart.setBackgroundImage();//设置背景图片
    localJFreeChart.setTitle(new TextTitle(localJFreeChart.getTitle().getText(), fontTitle));//设置标题字体样式
    
    
    /**
     * Returns the plot for the chart. 
     * The plot is a class responsible for coordinating the visual representation of the data, 
     * including the axes (if any).
     =============================================================================================*/
    CategoryPlot localCategoryPlot = (CategoryPlot)localJFreeChart.getPlot();
    
    
    
    
    /**
     * Returns the range axis for the plot. 
     * If the range axis for this plot is null, then the method will return the parent plot's 
     * range axis (if there is a parent plot).
     =============================================================================================*/
    NumberAxis localNumberAxis = (NumberAxis)localCategoryPlot.getRangeAxis();
    
    /**Sets the source for obtaining standard tick units for the axis,
     * and sends an AxisChangeEvent to all registered listeners. */
    localNumberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    localNumberAxis.setUpperMargin(0.15D);
    localNumberAxis.setLabelFont(font);
    
    
    
    
    
    /**
     * Returns a reference to the renderer for the plot.
     * =============================================================================================*/     
    CategoryItemRenderer localCategoryItemRenderer = localCategoryPlot.getRenderer();    
    localCategoryItemRenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    
    /**Sets a flag that controls the visibility of the item labels for a series.
     */
    localCategoryItemRenderer.setSeriesItemLabelsVisible(0, Boolean.TRUE); //设置柱体顶部显示数字
    localCategoryItemRenderer.setSeriesPaint(0, new Color(0,128,128));     //设置柱体颜色
    
    
    
    
    
    
    /**
     * Returns the domain axis for the plot. 
     * If the domain axis for this plot is null, then the method will return the parent 
     * plot's domain axis (if there is a parent plot).
     =============================================================================================*/
    
    
    
    CategoryAxis localCategoryAxis = localCategoryPlot.getDomainAxis();    
    localCategoryAxis.setLabelFont(font); //设置X轴标志字体
    //localCategoryAxis.setAxisLinePaint();
    //localCategoryAxis.setAxisLineStroke(stroke);
    // localCategoryAxis.setCategoryLabelPositionOffset(0);//设置类别标签距离X轴的高度
    localCategoryAxis.setUpperMargin(0.10);   //设置右边距
    localCategoryAxis.setCategoryMargin(0.55);//设置每个柱体的宽度(0.70 表示: 百分比)
    localCategoryAxis.setTickLabelFont(font);//设置X轴上的分类字体
    localCategoryAxis.setCategoryLabelPositions(CategoryLabelPositions.STANDARD);//设置X轴上的分类倾斜的角度
    
 
    
    return localJFreeChart;
  }

  public static JPanel createDemoPanel()
  {
    JFreeChart localJFreeChart = createChart(createDataset());
    return new ChartPanel(localJFreeChart);
  }

  public static void main(String[] paramArrayOfString)
  {
    BarChartDemo8 localBarChartDemo8 = new BarChartDemo8("JFreeChart: BarChartDemo8.java");
    localBarChartDemo8.pack();
    RefineryUtilities.centerFrameOnScreen(localBarChartDemo8);
    localBarChartDemo8.setVisible(true);
  }
}

















  • 大小: 13.3 KB
分享到:
评论

相关推荐

    JFreeChar柱状图实例

    jfreeChar 柱状图应用的一个实例,

    jfreeChar 折线图+柱形图(混合图) +最新Jar包及例子

    因为最近要用混合图,网上找了一些资料,研究jfreechar 混合图 折线图+柱形图(在一个图中展示,双Y轴,共用X轴,能适用于大部分功能) 别加上 jfreechar的文档

    jfreechar 实现生成柱状图,饼图,曲线,

    jfreechar 实现生成柱状图,饼图,曲线,没有调用正在的数据库数据,用的到的可以看看。

    JFreeChar 动态横向柱状图

    JFreeChar 动态横向柱状图,带纵向滚动条,可根据数据自动计算滚动条长度,可自定义系统柱子颜色,定时刷新

    JFreeChar制作饼图和柱状图

    JFreeChar制作饼图和柱状图 需要jcommon-1.0.0-rc1.jar包和jfreechart-1.0.0-rc1.jar包

    JFreeChar图表生成柱状图和饼状图源码

    JFreeChar图表生成柱状图和饼状图实例源代码。

    jfreechar统计图操作技巧

    运用jfreechar插件在项目开发中针对数据库数据进行统计,将数据信息一统计图的方式显示出来,主要有:柱状图,饼图,线形图...

    使用JFreeChar简单实现图表

    使用JFreeChar,实现柱状图,饼形图,线性图

    jfreechar 整合struts2.1.8版本生成线图,饼图,柱形图

    jfreechar 整合struts2.1.8版本生成线图,饼图,柱形图 直接导入eclipse 或myeclipse 即可运行,里面含有lib ,及运行详细说 如:<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts ...

    jfreechar画图源代码

    包含所有的jfreechar画的饼状图、柱状图、曲线图所有代码都是本人自己编写并且能运行出结果的。

    java实现柱状图

    java实现柱状图、饼状图、曲线图等。一个简单的java类就搞定。再加一个jar

    JFreeChar 图形拖拉

    发现有关JFreeChar 拖拉的东西网上资源忒少,所以就花了点时间去研究了一下。这里面有柱状图,甘特图,折线图等拖拉的例子,相信对那些正在研究JFreeChar 和正在为JFreeChar 图形拖拉问题困扰的人有所帮助。

    jfreecharAPI

    JFreeChart它主要是用来制作各种各样的图表,这些图表包括:饼图、柱状图(普通柱状图以及堆栈柱状图)、线图、区域图、分布图、混合图、甘特图以及一些仪表盘等等。

    jfreechar最新jar包

    bar charts (regular and stacked, with an optional 3D effect):柱状图 line and area charts:曲线图 scatter plots and bubble charts time series, high/low/open/close charts and candle stick charts:...

    JFreechar使用文档

    生成饼状图 生成单组柱状图 生成单组柱状图 生成堆积柱状图 生成折线图 柱状图

    jfreechar的使用

    JFreeChart是开放源代码站点SourceForge.net上的一个JAVA项目,它主要用来各种各样的图表,这些图表包括:饼图、柱状图(普通柱状图以及堆栈柱状图)、线图、区域图、分布图、混合图、甘特图以及一些仪表盘等等。...

    jfreechart各类曲线图JSP代码

    饼图,柱形图,曲线图!JFreeChart是一组功能强大、灵活易用的Java绘图API,使用它可以生成多种通用性的报表,包括柱状图、饼图、曲线图、甘特图等。它能够用在Swing和Web等中制作自定义的图表或报表,并且得到广泛...

    JfreeChar示例

    直接导入myEclipse即可,采用jsp+servlet+dao框架

    java+jfreechar+svg

    我用java和jfreechar写的柱状图之后采用SVG显示出来。以用来业务展示希望对大家有帮助

    JfreeChar实例

    本JfreeChar实例介绍了三种常见的图例,即柱状图、线性图、饼状图,下载后导入eclipse工程中即可使用

Global site tag (gtag.js) - Google Analytics