1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

JFreeChart-貸借対照表

Posted at

目次 ⇒ JFreeChartサンプル

package jp.avaj.lib.chart;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.Plot;
import org.jfree.chart.renderer.category.CategoryItemRenderer;
import org.jfree.chart.renderer.category.StackedBarRenderer;
import org.jfree.data.category.DefaultCategoryDataset;

import jp.avaj.lib.algo.ArMap;
import jp.avaj.lib.algo.ArTuple;
import jp.avaj.lib.algo.ArValidator;

/**
■ JFreeChart-貸借対照表

 */
public class Chart90_貸借対照表 {
  // 目次-雑多
  A_Chart90 a_Chart90;
  // 目次-Artery-JFreeChart用のライブラリ
  A_Chart00 a_LibChartSampeContents;

  public static void main(String[] args) {
    // 棒グラフなのでDefaultCategoryDatasetを使用する
    DefaultCategoryDataset ds = createDataset();
    // 軸の設定
    CategoryAxis catAxis = new CategoryAxis();
    NumberAxis numAxis = new NumberAxis();
    // 積上棒グラフにはStackedBarRendererを使用する
    StackedBarRenderer renderer = new StackedBarRenderer();
    // Plotを作成してグラフを表示する
    CategoryPlot catPlot = new CategoryPlot(ds,catAxis,numAxis,(CategoryItemRenderer)renderer);
    JFreeChart jfreeChart = new JFreeChart("貸借対照表",(Plot)catPlot);
    ChartFrame cFrame = new ChartFrame("貸借対照表",(JFreeChart)jfreeChart);
    cFrame.pack();
    cFrame.setVisible(true);
  }

  /** 貸借対照表データをCategoryDatasetに変換する */
  private static DefaultCategoryDataset createDataset() {
    // 科目を抽出するArValidator
    MyValidator validator = new MyValidator();
    // 作成するDataset
    DefaultCategoryDataset ds = new DefaultCategoryDataset();
    // 貸借対照データの取得
    Map<String,ArTuple<Integer,Status>> bsData = createBSData();
    // 資産・固定資産
    {
      validator.setStatus(Status.KOTEI_SHISAN);
      Map<String,ArTuple<Integer,Status>> data = ArMap.selectByValue(bsData,validator);
      addToDataset(ds,"借方",data);
    }
    // 資産・流動資産
    {
      validator.setStatus(Status.RYUUDOU_SHISAN);
      Map<String,ArTuple<Integer,Status>> data = ArMap.selectByValue(bsData,validator);
      addToDataset(ds,"借方",data);
    }
    // 純資産
    {
      validator.setStatus(Status.JUN_SHISAN);
      Map<String,ArTuple<Integer,Status>> data = ArMap.selectByValue(bsData,validator);
      addToDataset(ds,"貸方",data);
    }
    // 負債・固定負債
    {
      validator.setStatus(Status.KOTEI_FUSAI);
      Map<String,ArTuple<Integer,Status>> data = ArMap.selectByValue(bsData,validator);
      addToDataset(ds,"貸方",data);
    }
    // 負債・流動負債
    {
      validator.setStatus(Status.RYUUDOU_FUSAI);
      Map<String,ArTuple<Integer,Status>> data = ArMap.selectByValue(bsData,validator);
      addToDataset(ds,"貸方",data);
    }

    return ds;
  }

  private static void addToDataset(DefaultCategoryDataset ds,String kariKashi,Map<String,ArTuple<Integer,Status>> data) {
    Set<String> parties = data.keySet();
    for (String party : parties) {
      ds.addValue(data.get(party).getV0(),party,kariKashi);
    }
  }

  /** 貸借対照表データを作成する */
  private static Map<String,ArTuple<Integer,Status>> createBSData() {
    Map<String,ArTuple<Integer,Status>> map = new HashMap<String,ArTuple<Integer,Status>>();
    // 資産・流動資産
    map.put("現金・預金",new ArTuple<Integer,Status>(150000,Status.RYUUDOU_SHISAN));
    map.put("受取手形",new ArTuple<Integer,Status>(130000,Status.RYUUDOU_SHISAN));
    map.put("売掛金",new ArTuple<Integer,Status>(100000,Status.RYUUDOU_SHISAN));
    map.put("有価証券",new ArTuple<Integer,Status>(30000,Status.RYUUDOU_SHISAN));
    map.put("商品",new ArTuple<Integer,Status>(10000,Status.RYUUDOU_SHISAN));
    // 資産・固定資産
    map.put("土地",new ArTuple<Integer,Status>(180000,Status.KOTEI_SHISAN));
    map.put("建物",new ArTuple<Integer,Status>(230000,Status.KOTEI_SHISAN));
    map.put("機械",new ArTuple<Integer,Status>(120000,Status.KOTEI_SHISAN));
    // 負債・流動負債
    map.put("支払手形",new ArTuple<Integer,Status>(80000,Status.RYUUDOU_FUSAI));
    map.put("買掛金",new ArTuple<Integer,Status>(55000,Status.RYUUDOU_FUSAI));
    map.put("短期借入金",new ArTuple<Integer,Status>(20000,Status.RYUUDOU_FUSAI));
    // 負債・固定負債
    map.put("長期借入金",new ArTuple<Integer,Status>(120000,Status.KOTEI_FUSAI));
    map.put("社債",new ArTuple<Integer,Status>(200000,Status.KOTEI_FUSAI));
    // 純資産
    map.put("資本金",new ArTuple<Integer,Status>(360000,Status.JUN_SHISAN));
    map.put("利益剰余金",new ArTuple<Integer,Status>(115000,Status.JUN_SHISAN));
    //
    return map;
  }

  /** 科目抽出のArValidator */
  private static class MyValidator implements ArValidator<ArTuple<Integer,Status>>  {
    @Override
    public boolean check(ArTuple<Integer, Status> value) {
      return value.getV1() == status;
    }
    public void setStatus(Status status) {
      this.status = status;
    }
    private Status status;
  }

  /** 資産、負債、純資産 */
  static enum Status {
    /** 流動資産 */
    RYUUDOU_SHISAN,
    /** 固定資産 */
    KOTEI_SHISAN,
    /** 流動負債 */
    RYUUDOU_FUSAI,
    /** 固定負債 */
    KOTEI_FUSAI,
    /** 純資産 */
    JUN_SHISAN;
  }
}

無題.png

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?