JFreeChart(二)

package com.supcon.contingency.util;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.geom.Ellipse2D;
import java.io.UnsupportedEncodingException;
import java.util.List;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.StandardChartTheme;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.labels.StandardCategoryToolTipGenerator;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.SpiderWebPlot;
import org.jfree.chart.renderer.category.LineAndShapeRenderer;
import org.jfree.chart.title.LegendTitle;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.RectangleEdge;

import com.supcon.honcomb.basearchives.entity.CalibrationSpiderWebPlot;
import com.supcon.honcomb.utils.UtilTool;
import com.supermap.data.Point2D;
import com.supermap.data.Rectangle2D;

public class JFreeChartTool {
 public static JFreeChart ToLineChart(List list) {
  DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset();
  String COUNT = "";
  String DEPTNAME = "";
  String YEAR = "";
  String SUMMARYNAME = "";
  for (int i = 0; i < list.size(); i++) {
   Object[] objs = (Object[]) list.get(i);
   defaultcategorydataset.addValue(Double.valueOf(objs[1].toString()),
     "本月", objs[2].toString());
   defaultcategorydataset.addValue(Double.valueOf(objs[0].toString()),
     "去年同比", objs[2].toString());
   COUNT = objs[3].toString();
   YEAR = objs[4].toString();
   DEPTNAME = objs[5].toString();
   SUMMARYNAME = objs[6].toString();
   try {
    COUNT = UtilTool.toGBK(COUNT);
    DEPTNAME = UtilTool.toGBK(DEPTNAME);
    SUMMARYNAME = UtilTool.toGBK(SUMMARYNAME);
   } catch (UnsupportedEncodingException e) {
    e.printStackTrace();
   }
  }
  JFreeChart jfreechart = ChartFactory.createLineChart(YEAR + "年"
    + DEPTNAME + SUMMARYNAME + "趋势分析(" + COUNT + ")", null, COUNT,
    defaultcategorydataset, PlotOrientation.VERTICAL, true, true,
    false);
  // jfreechart.addSubtitle(new
  // TextTitle("Number of Classes By Release"));
  CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
  categoryplot.setRangePannable(true);
  categoryplot.setRangeGridlinesVisible(false);
  NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
  numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
  ChartUtilities.applyCurrentTheme(jfreechart);
  LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer) categoryplot
    .getRenderer();
  lineandshaperenderer.setBaseShapesVisible(true);
  lineandshaperenderer.setDrawOutlines(true);
  lineandshaperenderer.setUseFillPaint(true);
  lineandshaperenderer.setBaseFillPaint(Color.white);
  lineandshaperenderer.setSeriesStroke(0, new BasicStroke(3F));
  lineandshaperenderer.setSeriesOutlineStroke(0, new BasicStroke(2.0F));
  lineandshaperenderer.setSeriesShape(0,
    new java.awt.geom.Ellipse2D.Double(-5D, -5D, 10D, 10D));
  CategoryPlot plot = jfreechart.getCategoryPlot();
  CategoryAxis domainAxis = plot.getDomainAxis();
  jfreechart.getTitle().setFont(new Font("黑体", Font.BOLD, 20));
  jfreechart.getLegend().setItemFont(new Font("宋体", Font.PLAIN, 12));
  numberaxis.setLabelFont(new Font("宋体", Font.PLAIN, 12));
  domainAxis.setTickLabelFont(new Font("宋体", Font.PLAIN, 12));
  domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
  return jfreechart;
 }

 public static JFreeChart toSpiderChart(List list) {
  String DEPTNAME = "";
  DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset();
  for (int i = 0; i < list.size(); i++) {
   Object[] objs = (Object[]) list.get(i);
   defaultcategorydataset.addValue(Double.parseDouble(objs[1]
     .toString()), "本月完成", objs[0].toString() + "("
     + objs[3].toString() + ")");
   defaultcategorydataset.addValue(Double.parseDouble(objs[2]
     .toString()), "同比完成", objs[0].toString() + "("
     + objs[3].toString() + ")");
   DEPTNAME = objs[4].toString();
  }
  CalibrationSpiderWebPlot spiderwebplot = new CalibrationSpiderWebPlot(
    defaultcategorydataset);
  // spiderwebplot.setStartAngle(54D);
  spiderwebplot.setInteriorGap(0.40000000000000002D);
  // 是否画环
  spiderwebplot.setDrawRing(true);
  spiderwebplot
    .setToolTipGenerator(new StandardCategoryToolTipGenerator());
  JFreeChart jfreechart = new JFreeChart(DEPTNAME + "综合分析指标",
    TextTitle.DEFAULT_FONT, spiderwebplot, false);
  LegendTitle legendtitle = new LegendTitle(spiderwebplot);
  legendtitle.setPosition(RectangleEdge.BOTTOM);
  jfreechart.addSubtitle(legendtitle);
  ChartUtilities.applyCurrentTheme(jfreechart);
  // 创建主题样式
  StandardChartTheme standardChartTheme = new StandardChartTheme("GBK");
  // 设置标题字体
  standardChartTheme.setExtraLargeFont(new Font("黑体", Font.BOLD, 20));
  // 设置图例的字体
  standardChartTheme.setRegularFont(new Font("宋书", Font.PLAIN, 15));
  // 设置轴向的字体
  standardChartTheme.setLargeFont(new Font("宋书", Font.PLAIN, 15));
  // 应用主题样式
  ChartFactory.setChartTheme(standardChartTheme);

  return jfreechart;
 };
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值