JFreeChat实例

public static JFreeChart createCategoryChart(String name,String category,String value,CategoryDataset categoryDataset,PlotOrientation po,boolean legend,boolean tooltip,boolean url){

JFreeChart chart = ChartFactory.createBarChart(
    name,     // 图表名称
    category, // X轴名称
    value,     // Y轴名称
    categoryDataset,   // 数据集
    po, // 图表方向
    legend,   // 图例
    tooltip,   // Tooltips
    url); //URL

CategoryPlot plot = (CategoryPlot)chart.getPlot();   
     
     setCategoryPlot(plot);

return chart;
}

/**
* 3D柱图
* @return
* @param name
* @param category
* @param value
* @param categoryDataset
* @param po
* @param legend
* @param tooltip
* @param url
* @return
*/
public static JFreeChart createCategoryChart3D(String name,String category,String value,CategoryDataset categoryDataset,PlotOrientation po,boolean legend,boolean tooltip,boolean url){

JFreeChart chart = ChartFactory.createBarChart3D(
          name, category, value,
          categoryDataset,
          po,
          legend, tooltip, url);

CategoryPlot plot = (CategoryPlot)chart.getPlot();   
     
     setCategoryPlot(plot);

return chart;
}

/**
* 2D条形图
* @return
*/
public static JFreeChart createBarChart(String name,String category,String value,CategoryDataset categoryDataset,PlotOrientation po,boolean legend,boolean tooltip,boolean url){

JFreeChart chart = ChartFactory.createBarChart(
          name, category, value,
          categoryDataset,
          PlotOrientation.HORIZONTAL,
          legend, tooltip, url);

CategoryPlot plot = (CategoryPlot)chart.getPlot();   
     
     setCategoryPlot(plot);
     
     plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

return chart;
}

/**
* 3D条形图
* @return
*/
public static JFreeChart createBarChart3D(String name,String category,String value,CategoryDataset categoryDataset,PlotOrientation po,boolean legend,boolean tooltip,boolean url){

JFreeChart chart = ChartFactory.createBarChart3D(
          name, category, value,
          categoryDataset,
          PlotOrientation.HORIZONTAL,
          legend, tooltip, url);

CategoryPlot plot = (CategoryPlot)chart.getPlot();   
     
     setCategoryPlot(plot);
     
     plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

return chart;
}

/**
* 2D线图
* @return
*/
public static JFreeChart createLineChart(String name,String category,String value,CategoryDataset categoryDataset,PlotOrientation po,boolean legend,boolean tooltip,boolean url){

JFreeChart chart = ChartFactory.createLineChart(
          name, category, value,
          categoryDataset,
          po,
          legend, tooltip, url);

CategoryPlot plot = (CategoryPlot)chart.getPlot();   
     
     setCategoryPlot(plot);
     
     LineAndShapeRenderer lineAndShapeRenderer = (LineAndShapeRenderer) plot.getRenderer();
     lineAndShapeRenderer.setShapesVisible(true);
     lineAndShapeRenderer.setShapesFilled(true);

return chart;
}

/**
* 3D线图
* @return
*/
public static JFreeChart createLineChart3D(String name,String category,String value,CategoryDataset categoryDataset,PlotOrientation po,boolean legend,boolean tooltip,boolean url){

JFreeChart chart = ChartFactory.createLineChart3D(
          name, category, value,
          categoryDataset,
          po,
          legend, tooltip, url);

CategoryPlot plot = (CategoryPlot)chart.getPlot();   
     
     setCategoryPlot(plot);

return chart;
}

/**
* Series线图
* @return
*/
public static JFreeChart createSeriesLineChart(String name,String category,String value,TimeSeriesCollection timeSeriesCollection,PlotOrientation po,boolean legend,boolean tooltip,boolean url){

JFreeChart chart = ChartFactory.createTimeSeriesChart(
          name, category, value,
          timeSeriesCollection,
          legend, tooltip, url);

return chart;
}

/**
* 面积图
* @return
*/
public static JFreeChart createAreaChart(String name,String category,String value,CategoryDataset categoryDataset,PlotOrientation po,boolean legend,boolean tooltip,boolean url){
JFreeChart chart = ChartFactory.createAreaChart(
          name, category, value,
          categoryDataset,
          po,
          legend, tooltip, url);

CategoryPlot plot = (CategoryPlot)chart.getPlot();   
     
     setCategoryPlot(plot);

return chart;
}

/**
* 瀑布图
* @return
*/
public static JFreeChart createWaterfallChart(String name,String category,String value,CategoryDataset categoryDataset,PlotOrientation po,boolean legend,boolean tooltip,boolean url){
JFreeChart chart = ChartFactory.createWaterfallChart(
          name, category, value,
          categoryDataset,
          po,
          legend, tooltip, url);

CategoryPlot plot = (CategoryPlot)chart.getPlot();   
     
     setCategoryPlot(plot);

return chart;
}

/**
* 2D饼图
* @return
*/
public static JFreeChart createPieChart(String name,PieDataset pieDataset,PlotOrientation po,boolean legend,boolean tooltip,boolean url){
JFreeChart chart = ChartFactory.createPieChart(
    name,
    pieDataset,
          legend, tooltip, url);
      
      PiePlot piePlot = (PiePlot) chart.getPlot();
     
      piePlot.setCircular(false);
      piePlot.setLabelGap(0.02);    
      return chart;
}

/**
* 3D饼图
* @return
*/
public static JFreeChart createPieChart3D(String name,PieDataset pieDataset,PlotOrientation po,boolean legend,boolean tooltip,boolean url){
JFreeChart chart = ChartFactory.createPieChart3D(
          name,
    pieDataset,
          legend, tooltip, url);
      
      PiePlot piePlot = (PiePlot) chart.getPlot();
     
      piePlot.setCircular(false);
      piePlot.setLabelGap(0.02);
      
      
            
      return chart;
}

   /**
    * 复合饼图
    * 12
    */
   public static JFreeChart createMultiplePieChart(String name,CategoryDataset categoryDataset,PlotOrientation po,boolean legend,boolean tooltip,boolean url){
     TableOrder order = TableOrder.BY_ROW;     
//     TableOrder order = TableOrder.BY_COLUMN;
     
     JFreeChart chart = ChartFactory.createMultiplePieChart(name,
             categoryDataset,
                        order, legend, tooltip, url);
     
     return chart;
   }
   
   /**
    * 复合饼图3D
    * 12
    */
   public static JFreeChart createMultiplePieChart3D(String name,CategoryDataset categoryDataset,PlotOrientation po,boolean legend,boolean tooltip,boolean url){
     TableOrder order = TableOrder.BY_ROW;     
//     TableOrder order = TableOrder.BY_COLUMN;
     
     JFreeChart chart = ChartFactory.createMultiplePieChart3D(name,
             categoryDataset,
                        order, legend, tooltip, url);
     
     return chart;
   }
   
   /**
    * 环形图
    */
   public static JFreeChart createRingChart(String name,PieDataset pieDataset,PlotOrientation po,boolean legend,boolean tooltip,boolean url){
     JFreeChart chart = ChartFactory.createRingChart(
             name,
         pieDataset,
         legend, tooltip, url);
     
     RingPlot ringPlot = (RingPlot) chart.getPlot();
     
     ringPlot.setBackgroundAlpha(1.0f);
     ringPlot.setCircular(false);
     ringPlot.setLabelGap(0.02);
     
     return chart;
   }
   
   /**
    * 散点图
    * 40
    */
   public static JFreeChart createScatterPlot(String name,String category,String value,XYSeriesCollection xYSeriesCollection,PlotOrientation po,boolean legend,boolean tooltip,boolean url){
     JFreeChart chart = ChartFactory.createScatterPlot(
         name, category, value,
         xYSeriesCollection,
         po,
         legend, tooltip, url);
     
     XYPlot xyPlot = chart.getXYPlot();
     
     setXYSeriesPlot(xyPlot);
     
     return chart;
   }
   
   /**
    * 组织图
    */
   public static JFreeChart createHistogram(String name,String category,String value,XYSeriesCollection xYSeriesCollection,PlotOrientation po,boolean legend,boolean tooltip,boolean url){
     JFreeChart chart = ChartFactory.createHistogram(
         name, category, value,
         xYSeriesCollection,
         po,
         legend, tooltip, url);
     
     XYPlot xyPlot = chart.getXYPlot();
     
     setXYSeriesPlot(xyPlot);
     
     return chart;
   }
   
   /**
    * 数据点阶梯图
    * 33
    */
   public static JFreeChart createXYStepChart(String name,String category,String value,XYSeriesCollection xYSeriesCollection,PlotOrientation po,boolean legend,boolean tooltip,boolean url){
     JFreeChart chart = ChartFactory.createXYStepChart(
       name, category, value,
       xYSeriesCollection,
         po,
         legend, tooltip, url);
     
     XYPlot xyPlot = chart.getXYPlot();
     
     setXYSeriesPlot(xyPlot);
     
     return chart;
   }
   
   /**
    * 堆积柱状图
    * 01
    */
   public static JFreeChart createStackedCategoryChart(String name,String category,String value,CategoryDataset categoryDataset,PlotOrientation po,boolean legend,boolean tooltip,boolean url){
     JFreeChart chart = ChartFactory.createStackedBarChart(
       name, category, value,
          categoryDataset,
         po,
         legend, tooltip, url);
     
     CategoryPlot plot = (CategoryPlot)chart.getPlot();   
     
     setCategoryPlot(plot);
     
     return chart;
   }
   
   /**
    * 堆积柱状图3D
    * 04
    */
   public static JFreeChart createStackedCategoryChart3D(String name,String category,String value,CategoryDataset categoryDataset,PlotOrientation po,boolean legend,boolean tooltip,boolean url){
     JFreeChart chart = ChartFactory.createStackedBarChart3D(
       name, category, value,
          categoryDataset,
         po,
         legend, tooltip, url);
     
     CategoryPlot plot = (CategoryPlot)chart.getPlot();   
     
     setCategoryPlot(plot);
     
     return chart;
   }
   
   /**
    * 堆积条形图
    * 21
    */
   public static JFreeChart createStackedBarChart(String name,String category,String value,CategoryDataset categoryDataset,PlotOrientation po,boolean legend,boolean tooltip,boolean url){
     JFreeChart chart = ChartFactory.createStackedBarChart(
       name, category, value,
          categoryDataset,
         po,
         legend, tooltip, url);
     
     CategoryPlot plot = (CategoryPlot)chart.getPlot();   
     
     setCategoryPlot(plot);
     
     plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);    
     
     return chart;
   }
   
   /**
    * 堆积条形图3D
    * 23
    */
   public static JFreeChart createStackedBarChart3D(String name,String category,String value,CategoryDataset categoryDataset,PlotOrientation po,boolean legend,boolean tooltip,boolean url){
     JFreeChart chart = ChartFactory.createStackedBarChart3D(
       name, category, value,
          categoryDataset,
         po,
         legend, tooltip, url);
     
     CategoryPlot plot = (CategoryPlot)chart.getPlot();   
     
     setCategoryPlot(plot);
     
     plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
     
     return chart;
   }
   
   /**
    * 堆积面积图
    * 53
    */
   public static JFreeChart createStackedAreaChart(String name,String category,String value,CategoryDataset categoryDataset,PlotOrientation po,boolean legend,boolean tooltip,boolean url){
     JFreeChart chart = ChartFactory.createStackedAreaChart(
       name, category, value,
          categoryDataset,
         po,
         legend, tooltip, url);
     
     CategoryPlot plot = (CategoryPlot)chart.getPlot();   
     
     setCategoryPlot(plot);
     
     return chart;
   }
   
   /**
    * XY数据点面积图
    * 52
    */
   public static JFreeChart createXYAreaChart(String name,String category,String value,XYSeriesCollection xYSeriesCollection,PlotOrientation po,boolean legend,boolean tooltip,boolean url){
     JFreeChart chart = ChartFactory.createXYAreaChart(
       name, category, value,
          xYSeriesCollection,
         po,
         legend, tooltip, url);
     
     XYPlot xyPlot = chart.getXYPlot();
     
     setXYSeriesPlot(xyPlot);
     
     return chart;
   }
   
   
   /**
    * XY数据点阶梯面积图
    * 51
    */
   public static JFreeChart createXYStepAreaChart(String name,String category,String value,XYSeriesCollection xYSeriesCollection,PlotOrientation po,boolean legend,boolean tooltip,boolean url){
     JFreeChart chart = ChartFactory.createXYStepAreaChart(
       name, category, value,
          xYSeriesCollection,
         po,
         legend, tooltip, url);
     
     XYPlot xyPlot = chart.getXYPlot();
     
     setXYSeriesPlot(xyPlot);
     
     return chart;
   }
   
   /**
    * XY数据点折线图
    * 32
    */
   public static JFreeChart createXYLineChart(String name,String category,String value,XYSeriesCollection xYSeriesCollection,PlotOrientation po,boolean legend,boolean tooltip,boolean url){
     JFreeChart chart = ChartFactory.createXYLineChart(
       name, category, value,
          xYSeriesCollection,
         po,
         legend, tooltip, url);
     
     XYPlot xyPlot = chart.getXYPlot();
     
     setXYSeriesPlot(xyPlot);
     
     XYItemRenderer lineAndShapeRenderer = (XYItemRenderer) xyPlot.getRenderer();      
     
     return chart;
   }
   
   /**
    * XY数据点柱状图
    * 05
    */
   public static JFreeChart createXYBarChart(String name,String category,String value,XYSeriesCollection xYSeriesCollection,PlotOrientation po,boolean legend,boolean tooltip,boolean url){
     JFreeChart chart = ChartFactory.createXYBarChart(
       name, category, true, value,
          xYSeriesCollection,
         po,
         legend, tooltip, url);
     
     XYPlot xyPlot = chart.getXYPlot();
     
     setXYSeriesPlot(xyPlot);
     
     return chart;
   }
   
   /**
    * 气泡图
    */
   public static JFreeChart createBubbleChart(String name,String category,String value,XYZDataset xYZDataset,PlotOrientation po,boolean legend,boolean tooltip,boolean url){
     JFreeChart chart = ChartFactory.createBubbleChart(
       name, category, value,
       xYZDataset,
         po,
         legend, tooltip, url);
     
     return chart;
   }
   
   /**
    * 数据点堆积面积图
    */
   public static JFreeChart createStackedXYAreaChart(String name,String category,String value,DefaultTableXYDataset defaultTableXYDataset,PlotOrientation po,boolean legend,boolean tooltip,boolean url){
     JFreeChart chart = ChartFactory.createStackedXYAreaChart(
        name, category, value,
        defaultTableXYDataset,
         po,
         legend, tooltip, url);
     
     XYPlot xyPlot = chart.getXYPlot();
     
     setXYSeriesPlot(xyPlot);
     
     return chart;
   }
   
   /**
    * 甘特图
    */
   public static JFreeChart createGanttChart(String name,String category,String value,GanttCategoryDataset ganttCategoryDataset,PlotOrientation po,boolean legend,boolean tooltip,boolean url){
     JFreeChart chart = ChartFactory.createGanttChart(
       name, category, value,
       ganttCategoryDataset,
         legend, tooltip, url);
     
     CategoryPlot plot = (CategoryPlot) chart.getPlot();
     
     setCategoryPlot(plot);
     
     return chart;
   }
   
   /**
    * 股价图
    */
   public static JFreeChart createHighLowChart(String name,String category,String value,DefaultOHLCDataset defaultOHLCDataset,PlotOrientation po,boolean legend,boolean tooltip,boolean url){
     JFreeChart chart = ChartFactory.createHighLowChart(
       name, category, value,
       defaultOHLCDataset,
         false);
     
     return chart;
   }
   
   /**
    * 烛台图
    */
   public static JFreeChart createCandlestickChart(String name,String category,String value,DefaultOHLCDataset defaultOHLCDataset,PlotOrientation po,boolean legend,boolean tooltip,boolean url){
     JFreeChart chart = ChartFactory.createCandlestickChart(
       name, category, value,
       new ChartDataSet().getDefaultOHLCDataset(),
         false);
     return chart;
   }
   /**
    * 雷达图
    * @return
    */
   public static JFreeChart createPolarChart(String name,XYSeriesCollection xYSeriesCollection,PlotOrientation po,boolean legend,boolean tooltip,boolean url){
     JFreeChart chart = ChartFactory.createPolarChart(
         name,
         xYSeriesCollection,
         legend, tooltip, url);
     return chart;
   }
   
   /**
    * 2D柱线图
    */
   public static JFreeChart createCombinedChart(String name,String category,String value,CategoryDataset categoryDataset,PlotOrientation po,boolean legend,boolean tooltip,boolean url){
     JFreeChart chart = ChartFactory.createBarChart(
       name, category, value,
       categoryDataset,
         po,
         legend, tooltip, url);   
     
     CategoryPlot plot = (CategoryPlot)chart.getPlot();   
     
     setCategoryPlot(plot);
     
     BarRenderer barRenderer = (BarRenderer) plot.getRenderer();
     barRenderer.setMaximumBarWidth(0.10D);
     barRenderer.setItemMargin(0.10D);
     
     NumberAxis numberAxis = new NumberAxis("");
     plot.setRangeAxis(1, numberAxis);
     plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);
     plot.setDataset(1, categoryDataset);
     plot.setRenderer(1, new LineAndShapeRenderer());    
     plot.mapDatasetToDomainAxis(1, 0);
     plot.mapDatasetToRangeAxis(1,1);     
     
     return chart;
   }



   /**
    * 设置CategoryPlot
    * 坐标轴及网格属性设置
    * @param plot
    */
   private static void setCategoryPlot(CategoryPlot plot){
     plot.getDomainAxis().setVisible(true);
     plot.getDomainAxis().setLabelFont(new Font("宋体", Font.PLAIN, 12));
     plot.getDomainAxis().setLabelPaint(Color.BLACK);
     plot.getDomainAxis().setTickLabelFont(new Font("宋体", Font.PLAIN, 12));
     plot.getDomainAxis().setTickLabelPaint(Color.BLACK);
     plot.getDomainAxis().setTickLabelsVisible(true);
     
     plot.getRangeAxis().setVisible(true);
     plot.getRangeAxis().setLabelFont(new Font("宋体", Font.PLAIN, 12));
     plot.getRangeAxis().setLabelPaint(Color.BLACK);
     plot.getRangeAxis().setTickLabelFont(new Font("宋体", Font.PLAIN, 12));
     plot.getRangeAxis().setTickLabelPaint(Color.BLACK);
     plot.getRangeAxis().setVerticalTickLabels(false);
     plot.getRangeAxis().setLabelAngle(0.0D);
     
     NumberAxis   numberaxis   =   (NumberAxis)plot.getRangeAxis();   
     numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());


     plot.setDomainGridlinesVisible(true);
     plot.setRangeGridlinesVisible(true);
   }
   
   /**
    * 设置 XYPlot
    * @param plot
    */
   private static void setXYSeriesPlot(XYPlot plot){
     plot.getDomainAxis().setVisible(true);
     plot.getDomainAxis().setLabelFont(new Font("宋体", Font.PLAIN, 12));
     plot.getDomainAxis().setLabelPaint(Color.BLACK);
     plot.getDomainAxis().setTickLabelFont(new Font("宋体", Font.PLAIN, 12));
     plot.getDomainAxis().setTickLabelPaint(Color.BLACK);
     plot.getDomainAxis().setTickLabelsVisible(true);
     
     plot.getRangeAxis().setVisible(true);
     plot.getRangeAxis().setLabelFont(new Font("宋体", Font.PLAIN, 12));
     plot.getRangeAxis().setLabelPaint(Color.BLACK);
     plot.getRangeAxis().setTickLabelFont(new Font("宋体", Font.PLAIN, 12));
     plot.getRangeAxis().setTickLabelPaint(Color.BLACK);
     plot.getRangeAxis().setVerticalTickLabels(false);
     plot.getRangeAxis().setLabelAngle(0.0D);
     
     
     plot.setDomainGridlinesVisible(true);
     plot.setRangeGridlinesVisible(true);
   }

}

==================================================================================================
Jfreechart柱形图详细设置
发布日期:11-06-28 10:52    文章来源:互联网
一. 下载与环境配置
此最新版本为 1.0.13
解压jfreechart-1.0.13.zip 将lib目录下的jfreechart-1.0.13.jar 、jcommon-1.0.16.jar 复制到工程 WEB-INF\lib 文件夹中
二. 配置
我是用Struts1.2开发的。
在工程的web.xml 文件中添加
<servlet>
??????????? <servlet-name>DisplayChart</servlet-name>
??????????? <servlet-class>org.jfree.chart.servlet.DisplayChart</servlet-class>
??? </servlet>
??? <servlet-mapping>
??????????? <servlet-name>DisplayChart</servlet-name>
??????????? <url-pattern>/DisplayChart</url-pattern>
??? </servlet-mapping>
三. 生成柱形图
新建个Action 最好是继承DispatchAction
public ActionForward toBarPic(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
//添加数据
dataset.addValue(440, "数据", "类型1");
dataset.addValue(360, "数据", "类型2");
dataset.addValue(510, "数据", "类型3");
dataset.addValue(390, "数据", "类型4");
??????? //
JFreeChart? chart = ChartFactory.createBarChart3D("XXX统计图", "类型","数据额", dataset, PlotOrientation.VERTICAL, true, false, false);
HttpSession session=request.getSession();
String filename="";
try{
//生成宽600,高420 png格式的图,并将图片保存到session中,好像只能保存到session中,要不就设置为null
filename = ServletUtilities.saveChartAsPNG(chart,600,420, null, session);
}catch(Exception ex){
ex.printStackTrace();
}
String graphURL = request.getContextPath() + "/DisplayChart?filename=" + filename;
??????? request.setAttribute("graphURL", graphURL);
??????? request.setAttribute("filename", filename);
return mapping.findForward("success");
}
页面中 图片链接方式
?? <img src="${graphURL}" width=630 height=450 border=0 usemap="#${filename}">
生成的图如下:

可见生成柱形图很简单,只需要以下几步
1、 DefaultCategoryDataset dataset = new DefaultCategoryDataset();
2、 dataset.addValue(440, "数据", "类型1"); //封数据
3、 JFreeChart? chart = ChartFactory.createBarChart3D("XXX统计图", "类型","数据额", dataset, PlotOrientation.VERTICAL, true, false, false);
4、 String filename = ServletUtilities.saveChartAsPNG(chart,600,420, null, session);//返回图片名称
//为图片生成url访问地址
5、 String graphURL = request.getContextPath() + "/DisplayChart?filename=" + filename;
6、 将 图片名称filename 和图片地址 graphURL 保存到作用域中,最后返回。
以上是生成柱形图最基本的步骤,但是生成的图往往是不合人意的,因为太粗糙了,好比刚盖好的房子还没有装修,下面就对图形进行美化,装修这个柱形房子。
要设置图片高级属性先获得 CategoryPlot 和 BarRenderer3D 大部分修改都是在这上面
CategoryPlot plot = chart.getCategoryPlot();//设置图的高级属性
? BarRenderer3D renderer = new BarRenderer3D();//3D属性修改
最后还得将renderer 放到plot 中
? plot.setRenderer(renderer);//将修改后的属性值保存到图中
在JFreeChart? chart = ChartFactory.createBarChart3D()下面添加
CategoryPlot plot = chart.getCategoryPlot();//设置图的高级属性
? BarRenderer3D renderer = new BarRenderer3D();//3D属性修改
plot.setRenderer(renderer);//将修改后的属性值保存到图中
然后做的修改都是在
BarRenderer3D renderer = new BarRenderer3D();//3D属性修改
plot.setRenderer(renderer);//将修改后的属性值保存到图中
这两行中间,也就是以下添加的任何代码都是在上面这两行中间添加。
首先修改颜色
?
????????? //设置网格竖线颜色
? plot.setDomainGridlinePaint(Color.blue);
? plot.setDomainGridlinesVisible(true);
????????? //设置网格横线颜色
? plot.setRangeGridlinePaint(Color.blue);
? plot.setRangeGridlinesVisible(true);
????????? //图片背景色
? plot.setBackgroundPaint(Color.LIGHT_GRAY);
? plot.setOutlineVisible(true);
????????? //图边框颜色
? plot.setOutlinePaint(Color.magenta);
????????? //边框颜色
? renderer.setBaseOutlinePaint(Color.ORANGE);
? renderer.setDrawBarOutline(true);
????????? //设置墙体颜色
? renderer.setWallPaint(Color.gray);
效果图如下

?
接下来修改字体,看上图还是乱码,下面就对字体做调整
??? //对X轴做操作
CategoryAxis domainAxis = plot.getDomainAxis();
//对Y轴做操作
ValueAxis rAxis = plot.getRangeAxis();
?
/*----------设置消除字体的锯齿渲染(解决中文问题)--------------*/
????? chart.getRenderingHints().put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
?????
//设置标题字体
TextTitle textTitle = chart.getTitle();
textTitle.setFont(new Font("黑体", Font.PLAIN, 20));
//设置X轴坐标上的文字
domainAxis.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 11));
//设置X轴的标题文字
domainAxis.setLabelFont(new Font("宋体", Font.PLAIN, 12));
//设置Y轴坐标上的文字
rAxis.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 12));
//设置Y轴的标题文字
rAxis.setLabelFont(new Font("黑体", Font.PLAIN, 12));?????
//底部汉字乱码的问题?
chart.getLegend().setItemFont(new Font("宋体",Font.PLAIN,12));
效果图如下

在上面基础上在做一下高级设计,设计字体颜色和节段
//对X轴做操作
? CategoryAxis domainAxis = plot.getDomainAxis();
? //对Y轴做操作
? ValueAxis rAxis = plot.getRangeAxis();
?
? /*--------设置消除字体的锯齿渲染(解决中文问题)---------*/
?? chart.getRenderingHints().put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
?????
????? //设置标题字体
????? TextTitle textTitle = chart.getTitle();
????? textTitle.setFont(new Font("黑体", Font.PLAIN, 20));
????????? textTitle.setBackgroundPaint(Color.LIGHT_GRAY);//标题背景色
????????? textTitle.setPaint(Color.cyan);//标题字体颜色
????????? textTitle.setText("类型统计图");//标题内容?
????? //设置X轴坐标上的文字
domainAxis.setTickLabelFont(new Font("宋体", Font.PLAIN, 11));
????? //设置X轴的标题文字
????? domainAxis.setLabelFont(new Font("宋体", Font.PLAIN, 12));
?????
????? domainAxis.setTickLabelPaint(Color.red);//X轴的标题文字颜色
????? domainAxis.setTickLabelsVisible(true);//X轴的标题文字是否显示
????? domainAxis.setAxisLinePaint(Color.red);//X轴横线颜色
????? domainAxis.setTickMarksVisible(true);//标记线是否显示
????? domainAxis.setTickMarkOutsideLength(3);//标记线向外长度
????? domainAxis.setTickMarkInsideLength(3);//标记线向内长度
????? domainAxis.setTickMarkPaint(Color.red);//标记线颜色
????? /**? Y轴设计同X轴相类似? **/
????? //设置Y轴坐标上的文字
????? rAxis.setTickLabelFont(new Font("宋体", Font.PLAIN, 12));
????? rAxis.setMinorTickCount(7);//显示有多少标记段
????? rAxis.setMinorTickMarksVisible(true);
rAxis.setRange(100, 600); //Y轴取值范围(或者如下设置)
???? // rAxis.setLowerBound(100);? //Y轴以开始的最小值
???? // rAxis.setUpperBound(600);Y轴的最大值
????? //设置Y轴的标题文字
????? rAxis.setLabelFont(new Font("黑体", Font.PLAIN, 12));?????
???? //底部汉字乱码的问题?
???? chart.getLegend().setItemFont(new Font("宋体",Font.PLAIN,12));

?
大多数情况下都需要在柱子上显示对应的数值,设置如下:
?????? renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
?? renderer.setBaseItemLabelsVisible(true);
?? renderer.setBaseItemLabelPaint(Color.BLUE);//设置数值颜色,默认黑色
?? 用下面设置也能达到同样效果
?????? renderer.setItemLabelGenerator( new? StandardCategoryItemLabelGenerator());
renderer.setItemLabelsVisible( true );
renderer.setItemLabelPaint(Color.BLUE);
效果图如下:
?
默认的数值如上图所示,但是大多数情况下我们要应对不同的需求对数值显示的位置等进行调整。具体调整如下:
???????? //搭配ItemLabelAnchor TextAnchor 这两项能达到不同的效果,但是
ItemLabelAnchor最好选OUTSIDE,因为INSIDE显示不出来
renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.CENTER_LEFT));
???? //下面可以进一步调整数值的位置,但是得根据ItemLabelAnchor选择情况,例
如我选的是OUTSIDE12,那么下面设置为正数时,数值就会向上调整,负数则向下
?????? renderer.setItemLabelAnchorOffset(10);
效果图如图六:

有时候柱子过多,而且图大小有限,就得将柱子类型倾斜显示,或者将其放到上面等。看如下配置:
??? //将类型放到上面
plot.setDomainAxisLocation(AxisLocation.TOP_OR_RIGHT);
??? //横轴上的 Lable 45度倾斜
????? domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);
//将默认放到左边的数值放到右边
plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);
效果图如下:
?
看上面的柱子太粗,实在不好看,下面就是调整柱子的宽度和透明度等:
?????????? //设置距离图片左端距离
????? domainAxis.setUpperMargin(0.2);
?????? //设置距离图片右端距离
????? domainAxis.setLowerMargin(0.2);
????????? //数据轴精度
???? ? NumberAxis na = (NumberAxis) plot.getRangeAxis();
????????? na.setAutoRangeIncludesZero(true);
????? DecimalFormat df = new DecimalFormat("#0.000");
????? //数据轴数据标签的显示格式
????? na.setNumberFormatOverride(df);
????????? //设置柱的透明度
????? plot.setForegroundAlpha(1.0f);
?
详细设置如下:DefaultCategoryDataset dataset = new DefaultCategoryDataset();
//添加数据
dataset.addValue(440, "数据", "类型1");
dataset.addValue(360, "数据", "类型2");
dataset.addValue(510, "数据", "类型3");
dataset.addValue(390, "数据", "类型4");
/**参数分别为:图表标题 ,目录轴的显示标签 ,数值轴的显示标签 ,数据集 ,是否生成URL链接
图表方向:水平、垂直, 是否显示图例(对于简单的柱状图必须是false) ,是否生成工具 */
JFreeChart chart = ChartFactory.createBarChart3D("XXX统计图", "类型","数据额", dataset, PlotOrientation.VERTICAL, true, false, true);
/*----------设置消除字体的锯齿渲染(解决中文问题)--------------*/
chart.getRenderingHints().put(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
//底部汉字乱码的问题
chart.getLegend().setItemFont(new Font("宋体",Font.PLAIN,12));
//设置标题字体
TextTitle textTitle = chart.getTitle();
textTitle.setFont(new Font("黑体", Font.PLAIN, 20));
textTitle.setBackgroundPaint(Color.LIGHT_GRAY);//标题背景色
textTitle.setPaint(Color.cyan);//标题字体颜色
textTitle.setText("类型统计图");//标题内容
CategoryPlot plot = chart.getCategoryPlot();//设置图的高级属性
BarRenderer3D renderer = new BarRenderer3D();//3D属性修改
CategoryAxis domainAxis = plot.getDomainAxis();//对X轴做操作
ValueAxis rAxis = plot.getRangeAxis();//对Y轴做操作
/***
* domainAxis设置(x轴一些设置)
**/
//设置X轴坐标上的文字
domainAxis.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 11));
//设置X轴的标题文字
domainAxis.setLabelFont(new Font("宋体", Font.PLAIN, 12));
domainAxis.setLabel("");//X轴的标题内容
domainAxis.setTickLabelPaint(Color.red);//X轴的标题文字颜色
domainAxis.setTickLabelsVisible(true);//X轴的标题文字是否显示
domainAxis.setAxisLinePaint(Color.red);//X轴横线颜色
domainAxis.setTickMarksVisible(true);//标记线是否显示
domainAxis.setTickMarkOutsideLength(3);//标记线向外长度
domainAxis.setTickMarkInsideLength(3);//标记线向内长度
domainAxis.setTickMarkPaint(Color.red);//标记线颜色
domainAxis.setUpperMargin(0.2);//设置距离图片左端距离
domainAxis.setLowerMargin(0.2); //设置距离图片右端距离
//横轴上的 Lable 是否完整显示
domainAxis.setMaximumCategoryLabelWidthRatio(0.6f);
//横轴上的 Lable 45度倾斜
domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);
/**
* rAxis设置 Y轴设置
*
**/
//设置Y轴坐标上的文字
rAxis.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 12));
//设置Y轴的标题文字
rAxis.setLabelFont(new Font("黑体", Font.PLAIN, 12));
//Y轴取值范围(下面不能出现 rAxis.setAutoRange(true) 否则不起作用)
rAxis.setRange(100, 600);
// rAxis.setLowerBound(100); //Y轴以开始的最小值
// rAxis.setUpperBound(600);//Y轴的最大值
rAxis.setLabel("content");//Y轴内容
rAxis.setLabelAngle(1.6);//标题内容显示角度(1.6时候水平)
rAxis.setLabelPaint(Color.red);//标题内容颜色
rAxis.setMinorTickMarksVisible(true);//标记线是否显示
rAxis.setMinorTickCount(7);//节段中的刻度数
rAxis.setMinorTickMarkInsideLength(3);//内刻度线向内长度
rAxis.setMinorTickMarkOutsideLength(3);//内刻度记线向外长度
rAxis.setTickMarkInsideLength(3);//外刻度线向内长度
rAxis.setTickMarkPaint(Color.red);//刻度线颜色
rAxis.setTickLabelsVisible(true);//刻度数值是否显示
// 所有Y标记线是否显示(如果前面设置rAxis.setMinorTickMarksVisible(true); 则其照样显示)
rAxis.setTickMarksVisible(true);
rAxis.setAxisLinePaint(Color.red);//Y轴竖线颜色
rAxis.setAxisLineVisible(true);//Y轴竖线是否显示
//设置最高的一个 Item 与图片顶端的距离 (在设置rAxis.setRange(100, 600);情况下不起作用)
rAxis.setUpperMargin(0.15);
//设置最低的一个 Item 与图片底端的距离
rAxis.setLowerMargin(0.15);
rAxis.setAutoRange(true);//是否自动适应范围
rAxis.setVisible(true);//Y轴内容是否显示
//数据轴精度
NumberAxis na = (NumberAxis) plot.getRangeAxis();
na.setAutoRangeIncludesZero(true);
DecimalFormat df = new DecimalFormat("#0.000");
//数据轴数据标签的显示格式
na.setNumberFormatOverride(df);
/**
* renderer设置 柱子相关属性设置
*/renderer.setBaseOutlinePaint(Color.ORANGE); //边框颜色
renderer.setDrawBarOutline(true);
renderer.setWallPaint(Color.gray);//设置墙体颜色
renderer.setMaximumBarWidth(0.08); //设置柱子宽度
renderer.setMinimumBarLength(0.1); //设置柱子高度
renderer.setSeriesPaint(0,Color.ORANGE); //设置柱的颜色
renderer.setItemMargin(0); //设置每个地区所包含的平行柱的之间距离
//在柱子上显示相应信息
renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
renderer.setBaseItemLabelsVisible(true);
renderer.setBaseItemLabelPaint(Color.BLACK);//设置数值颜色,默认黑色
//搭配ItemLabelAnchor TextAnchor 这两项能达到不同的效果,但是ItemLabelAnchor最好选OUTSIDE,因为INSIDE显示不出来
renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.CENTER_LEFT));
//下面可以进一步调整数值的位置,但是得根据ItemLabelAnchor选择情况.
renderer.setItemLabelAnchorOffset(10);
/**
* plot 设置
***/
//设置网格竖线颜色
plot.setDomainGridlinePaint(Color.blue);
plot.setDomainGridlinesVisible(true);
//设置网格横线颜色
plot.setRangeGridlinePaint(Color.blue);
plot.setRangeGridlinesVisible(true);
//图片背景色
plot.setBackgroundPaint(Color.LIGHT_GRAY);
plot.setOutlineVisible(true);
//图边框颜色
plot.setOutlinePaint(Color.magenta);
//设置柱的透明度
plot.setForegroundAlpha(1.0f);
//将类型放到上面
plot.setDomainAxisLocation(AxisLocation.TOP_OR_RIGHT);
//将默认放到左边的数值放到右边
plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);
plot.setRenderer(renderer);//将修改后的属性值保存到图中
HttpSession session=request.getSession();
String filename="";
try{
//生成宽600,高420 png格式的图,并将图片保存到session中,好像只能保存到session中,要不就设置为null
filename = ServletUtilities.saveChartAsPNG(chart,600,420, null, session);
}catch(Exception ex){
ex.printStackTrace();
}
String graphURL = request.getContextPath() + "/DisplayChart?filename=" + filename;
request.setAttribute("graphURL", graphURL);
request.setAttribute("filename", filename);
==============================================================================================================================================
设置折线图
//返回类型为图片类型
  response.setContentType("image/png");
  //设置返回字体
  response.setCharacterEncoding("utf-8");
  //获取数据对象
  CategoryDataset cd = getData();
  //创建图形对象
  JFreeChart jfc = ChartFactory.createLineChart("书籍组成变化", null, "组成量", cd, PlotOrientation.VERTICAL, true, true, false);
  //设置图例的字体显示,防止中文乱码
  jfc.getLegend().setItemFont(new Font("黑体", 0, 10));
  //设置标题并且设置其字体,防止中文乱码
  TextTitle textTitle = new TextTitle("书籍组成变化");
  textTitle.setFont(new Font("宋体", Font.BOLD, 12));
  jfc.setTitle(textTitle);
  //设置图表子标题
  jfc.addSubtitle(new TextTitle("按月份"));
  //创建一个标题对象,用于放置产生图形日前
  TextTitle tt = new TextTitle("日期:"+new Date());
  //设置该标题的字体,防止中文乱码
  tt.setFont(new Font("黑体", 0, 10));
  //设置该标题的位置为产生的图形下面
  tt.setPosition(RectangleEdge.BOTTOM);
  //设置图片为右对齐
  tt.setHorizontalAlignment(HorizontalAlignment.RIGHT);
  //将该标题添加到图表
  jfc.addSubtitle(tt);
  //设置整个图表的背景色为绿色
  jfc.setBackgroundPaint(Color.green);
  //获取图表区域对象
  CategoryPlot cp = jfc.getCategoryPlot();
  //设置图表区域背景色
  cp.setBackgroundPaint(Color.white);
  //设置边线不可见
  cp.setRangeGridlinesVisible(false);
        //设置横轴的字体,防止中文乱码
        cp.getDomainAxis().setTickLabelFont(new Font("黑体", 0, 10));
        //设置竖轴的字体,防止中文乱码
        cp.getRangeAxis().setLabelFont(new Font("黑体", 0, 10));
  //获取显示线条的对象
  LineAndShapeRenderer lasp = (LineAndShapeRenderer)cp.getRenderer();
  //设置拐点是否可见/是否显示拐点
  lasp.setBaseShapesVisible(true);
  //设置拐点不同用不同的形状
  lasp.setDrawOutlines(true);
  //设置线条是否被显示填充颜色
  lasp.setUseFillPaint(true);
  //设置拐点颜色
  lasp.setBaseFillPaint(Color.yellow);
  // 设置折线加粗
  lasp.setSeriesStroke(0, new BasicStroke(3F));
  lasp.setSeriesOutlineStroke(0, new BasicStroke(2.0F));
  // 设置折线拐点
  lasp.setSeriesShape(0,new java.awt.geom.Ellipse2D.Double(-5D, -5D, 10D, 10D));


  ========================================================================================================================================
  /****************************************************************************
 * Copyright (C) 2010-2011 Smartdot Beijing Software Co.,Ltd                *
 * All Rights Reserved.                                                        *
 * 本软件为北京慧点科技开发有限公司开发研制                                            *
 * 未经本公司正式书面同意,其他任何个人、团体不得使用、复制、修改或发布本软件                *
 ****************************************************************************/
package com.smartdot.iscm.service.appraise.impl;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;

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.ValueAxis;
import org.jfree.chart.labels.ItemLabelAnchor;
import org.jfree.chart.labels.ItemLabelPosition;
import org.jfree.chart.labels.StandardCategoryItemLabelGenerator;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer3D;
import org.jfree.chart.title.LegendTitle;
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.ui.TextAnchor;

public class TimeSeriesTest extends ApplicationFrame {
    /**
     *
     */
    private static final long serialVersionUID = 1L;

    public TimeSeriesTest(String title) {
        super(title);
        // TODO Auto-generated constructor stub
        CategoryDataset xydataset = createDataset();
        JFreeChart jfreechart = createChart(xydataset);
        ChartPanel chartpanel = new ChartPanel(jfreechart, false);
        chartpanel.setPreferredSize(new Dimension(500, 270));
        chartpanel.setMouseZoomable(true, false);
        setContentPane(chartpanel);
    }

    private static CategoryDataset createDataset() {
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        dataset.addValue(95, "合规率","集团");
        dataset.addValue(90,  "合规率","北京");
        dataset.addValue(88, "合规率","云南");
        return dataset;
    }

    @SuppressWarnings("deprecation")
    private static JFreeChart createChart(CategoryDataset xydataset) {
//        JFreeChart localChart = ChartFactory.createLineChart("合规评价", //图表标题   
//                "省公司", //数值轴的显示标签   
//                "控制点合规率(%)", //目录轴的显示标签   
//                xydataset, //数据   
//                //PlotOrientation.HORIZONTAL, //图表方向水平   
//                PlotOrientation.VERTICAL, //图表方向垂直   
//                true, //是否显示图例   
//                false, //是否显示工具提示   
//                false //是否生成URL
//                );
//        TextTitle title = localChart.getTitle();
//        title.setFont(new Font("宋体", Font.BOLD, 18));
//        LegendTitle legend = localChart.getLegend();
//        legend.setItemFont(new Font("宋体", Font.ITALIC, 14));
//        CategoryPlot plot = localChart.getCategoryPlot();
//        plot.setBackgroundPaint(null);
//        CategoryAxis domainAxis = plot.getDomainAxis();
//        Font xfont = new Font("宋体", Font.PLAIN, 12);
//        Font yfont = new Font("宋体", Font.PLAIN, 12);
//        localChart.setBackgroundPaint(Color.getColor("#EBEEF3"));//设置背景颜色
//        domainAxis.setLabelFont(xfont);// 轴标题
//        domainAxis.setTickLabelFont(xfont);// 轴数值
//        domainAxis.setTickLabelPaint(Color.BLUE); // 字体颜色
//        domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); // 横轴上的label斜显示
//        // Y 轴 setBackgroundPaint
//        ValueAxis rangeAxis = plot.getRangeAxis();
//        rangeAxis.setLabelFont(yfont);
//        // 设置绘图区背景色
//        plot.setBackgroundPaint(Color.LIGHT_GRAY);
//        // 设置水平方向背景线颜色
//        plot.setRangeGridlinePaint (Color.WHITE);
//        // 设置是否显示水平方向背景线,默认值为true
//        plot.setRangeGridlinesVisible(true);
//        // 设置垂直方向背景线颜色
//        plot.setDomainGridlinePaint(Color.WHITE);
//        // 设置是否显示垂直方向背景线,默认值为false
//        plot.setDomainGridlinesVisible(true);
//        // Y 轴 setBackgroundPaint
//        rangeAxis.setLabelFont(yfont);
//        // 是否显示零点
//        rangeAxis.setAutoRange(true);
//        // 设置坐标标记大小   
//        rangeAxis.setTickMarkStroke(new BasicStroke(1.6f));
//        //获取显示线条的对象
//          LineAndShapeRenderer lasp = (LineAndShapeRenderer)plot.getRenderer();
//          //设置拐点是否可见/是否显示拐点
//          lasp.setBaseShapesVisible(true);
//          //设置Y轴数值
//        rangeAxis.setRange(10,102);
//        return localChart;

            JFreeChart chart = ChartFactory.createBarChart3D(
                    "本次检查合规评价",
                    "", //数值轴的显示标签   
                    "控制点合规率(%)", //目录轴的显示标签   
                    xydataset, //数据   
                    //PlotOrientation.HORIZONTAL, //图表方向水平   
                    PlotOrientation.VERTICAL, //图表方向垂直   
                    true, //是否显示图例   
                    false, //是否显示工具提示   
                    false //是否生成URL
                      );
            
            TextTitle title = chart.getTitle();
            title.setFont(new Font("宋体", Font.BOLD, 20));
            LegendTitle legend = chart.getLegend();
            legend.setItemFont(new Font("宋体", Font.ITALIC, 16));
            //PiePlot pieplot=  jfreechart.getPlot();
            CategoryPlot plot = chart.getCategoryPlot();
//            XYPlot xyplot = jfreechart.getXYPlot();           
            BarRenderer3D renderer = new BarRenderer3D();//3D属性修改
            
            //renderer.setBaseOutlinePaint(Color.LIGHT_GRAY); //边框颜色
            //renderer.setDrawBarOutline(true);
            //renderer.setWallPaint(Color.decode("#EEEEF3"));//设置墙体颜色
            renderer.setMaximumBarWidth(0.1); //设置柱子宽度
            //renderer.setMinimumBarLength(0.1); //设置柱子高度
            //renderer.setSeriesPaint(0,Color.BLUE); //设置柱的颜色
            //renderer.setItemMargin(0); //设置每个地区所包含的平行柱的之间距离
            //在柱子上显示相应信息
            renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
            renderer.setBaseItemLabelsVisible(true);
            renderer.setBaseItemLabelPaint(Color.BLUE);//设置数值颜色,默认黑色
            //搭配ItemLabelAnchor TextAnchor 这两项能达到不同的效果,但是ItemLabelAnchor最好选OUTSIDE,因为INSIDE显示不出来
            renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_CENTER));
            //下面可以进一步调整数值的位置,但是得根据ItemLabelAnchor选择情况.
            //renderer.setItemLabelAnchorOffset(10);
            renderer.setItemLabelAnchorOffset(10D);
            
            
            // 设置绘图区背景色
            //plot.setBackgroundPaint(Color.LIGHT_GRAY);
            // 设置水平方向背景线颜色
            //plot.setRangeGridlinePaint(Color.WHITE);
            // 设置是否显示水平方向背景线,默认值为true
            //plot.setRangeGridlinesVisible(true);
            // 设置垂直方向背景线颜色
            //plot.setDomainGridlinePaint(Color.WHITE);
            // 设置是否显示垂直方向背景线,默认值为false
            plot.setDomainGridlinesVisible(true);
            plot.setRenderer(renderer);//将修改后的属性值保存到图中
            Font font = new Font("黑体", 10, 20);         
            CategoryAxis domainAxis = plot.getDomainAxis();
            domainAxis.setLabelFont(font); // 设置横轴字体
            domainAxis.setTickLabelFont(font);// 设置坐标轴标尺值字体
            domainAxis.setLowerMargin(0.01);// 左边距 边框距离
            domainAxis.setUpperMargin(0.06);// 右边距 边框距离,防止最后边的一个数据靠近了坐标轴。
            domainAxis.setMaximumCategoryLabelLines(2);   
            
            
            //plot.setBackgroundPaint(null);
            plot.setForegroundAlpha(1.0f);// 设置柱的透明度
            Font xfont = new Font("宋体", Font.PLAIN, 12);
            Font yfont = new Font("宋体", Font.PLAIN, 12);
            chart.setBackgroundPaint(Color.getColor("#EBEEF3"));//设置背景颜色
            domainAxis.setLabelFont(xfont);// 轴标题
            //plot.setToolTipGenerator(new StandardPieToolTipGenerator());
            domainAxis.setTickLabelFont(xfont);// 轴数值
            domainAxis.setTickLabelPaint(Color.BLUE); // 字体颜色
            domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); // 横轴上的label斜显示
            // Y 轴 setBackgroundPaint
            ValueAxis rangeAxis = plot.getRangeAxis();
            rangeAxis.setLabelFont(yfont);
            rangeAxis.setTickLabelFont(yfont);
            rangeAxis.setTickLabelPaint(Color.BLUE);
            // 是否显示零点
            rangeAxis.setAutoRange(true);
            // 设置坐标标记大小   
            rangeAxis.setTickMarkStroke(new BasicStroke(1.6f));     
            // 设置坐标标记颜色   
            //rangeAxis.setTickMarkPaint(Color.BLACK);  
             rangeAxis.setRange(0,110);
            return chart;
    }
    

    public static void main(String[] paramArrayOfString) {
        TimeSeriesTest dragValueApp = new TimeSeriesTest("1231231");
        dragValueApp.pack();
        RefineryUtilities.centerFrameOnScreen(dragValueApp);
        dragValueApp.setVisible(true);
    }
}

   集团 261

   dataset.addValue(88, "数据网管系统","2010年");
        dataset.addValue(90, "OA","2010年");
        dataset.addValue(98, "BOSS","2010年");
        dataset.addValue(88, "客户服务支撑系统","2010年");
        dataset.addValue(78,  "数据网管系统","2011年");
        dataset.addValue(84,  "OA","2011年");
        dataset.addValue(92,  "BOSS","2011年");
        dataset.addValue(94,  "客户服务支撑系统","2011年");
        dataset.addValue(88, "数据网管系统","2012年");
        dataset.addValue(79, "OA","2012年");
        dataset.addValue(99, "BOSS","2012年");
        dataset.addValue(95, "客户服务支撑系统","2012年");
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值