zoukankan      html  css  js  c++  java
  • 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;
     };
    }

  • 相关阅读:
    BootStrap Table前台和后台分页对JSON格式的要求
    神奇的外部嵌套(使用ROW_NUMBER()查询带条件的时候提示列名无效)
    要想获取select的值,使用ng-modle,否则无法获取select 的值
    Angular使用操作事件指令ng-click传多个参数示例
    Jenins 邮件通知
    Jenkins 流水线(Pipeline)
    Jenkins Master-Slave 架构
    Jenins 参数化构建
    Jenkins 用户权限管理
    Jenkins 安装
  • 原文地址:https://www.cnblogs.com/winkey4986/p/2721177.html
Copyright © 2011-2022 走看看