荒屋敷智也のブログ

【HTML】コピペOK!「投資資産状況のグラフ化」

当ブログではアフィリエイト広告を利用しています

f:id:zenryokusyounen:20210911163120p:plain

どうも、こんにちは。「荒屋敷智也のブログ」にお越し頂きありがとうございます。

最近いろいろな方の投資ブログを拝見させて頂いております。その中で自身の投資資産状況を投稿している方が多くみられます。

そういう投稿をしている方って主に、Excelにデータをまとめて、グラフ化してるのがほとんどですよね。別にそれでもいいんですけど、かっこよくしませんか?

投資資産状況をグラフ化した記事

arayashikitomoya.hatenablog.com

投資資産状況のグラフ化

今回、私は投資資産状況を投稿するために「amcharts」というWeb上グラフを描画するツールを使って、「投資資産状況のグラフ化」をしたのでコピペして使用してみてください。

<!-- Styles -->
<style>
#chartdiv {
  width: 100%;
  height: 500px;
}
</style>
<!-- Resources -->
<p>
<script src="https://cdn.amcharts.com/lib/4/core.js"></script>
<script src="https://cdn.amcharts.com/lib/4/charts.js"></script>
<script src="https://cdn.amcharts.com/lib/4/themes/animated.js"></script>
</p>
<!-- Chart code -->
<p>
<script>
am4core.ready(function() {

// Themes begin
am4core.useTheme(am4themes_animated);
// Themes end

// Create chart instance
var chart = am4core.create("chartdiv", am4charts.XYChart);

// Data for both series
var data = [ {
  "year": "2021",
  "income": 0,
  "expenses": 0
}, {
  "year": "May",
  "income": 300000,
  "expenses": 300000
}, {
  "year": "Jun",
  "income": 700000,
  "expenses": 720022
}, {
  "year": "Jul",
  "income": 1000000,
  "expenses": 1022519
},{
  "year": "Aug",
  "income": 1200000,
  "expenses": 1244650,
},{
  "year": "Sep",
  "income": 1200000,
  "expenses": 1282767,
}];

/* Create axes */
var categoryAxis = chart.xAxes.push(new am4charts.CategoryAxis());
categoryAxis.dataFields.category = "year";
categoryAxis.renderer.minGridDistance = 30;

/* Create value axis */
var valueAxis = chart.yAxes.push(new am4charts.ValueAxis());

/* Create series */
var columnSeries = chart.series.push(new am4charts.ColumnSeries());
columnSeries.name = "投資元本";
columnSeries.dataFields.valueY = "income";
columnSeries.dataFields.categoryX = "year";

columnSeries.columns.template.tooltipText = "[#fff font-size: 15px]{name} in {categoryX}:\n[/][#fff font-size: 20px]{valueY}[/] [#fff]{additional}[/]"
columnSeries.columns.template.propertyFields.fillOpacity = "fillOpacity";
columnSeries.columns.template.propertyFields.stroke = "stroke";
columnSeries.columns.template.propertyFields.strokeWidth = "strokeWidth";
columnSeries.columns.template.propertyFields.strokeDasharray = "columnDash";
columnSeries.tooltip.label.textAlign = "middle";

var lineSeries = chart.series.push(new am4charts.LineSeries());
lineSeries.name = "投資資産総額";
lineSeries.dataFields.valueY = "expenses";
lineSeries.dataFields.categoryX = "year";

lineSeries.stroke = am4core.color("#fdd400");
lineSeries.strokeWidth = 3;
lineSeries.propertyFields.strokeDasharray = "lineDash";
lineSeries.tooltip.label.textAlign = "middle";

var bullet = lineSeries.bullets.push(new am4charts.Bullet());
bullet.fill = am4core.color("#fdd400"); // tooltips grab fill from parent by default
bullet.tooltipText = "[#fff font-size: 15px]{name} in {categoryX}:\n[/][#fff font-size: 20px]{valueY}[/] [#fff]{additional}[/]"
var circle = bullet.createChild(am4core.Circle);
circle.radius = 4;
circle.fill = am4core.color("#fff");
circle.strokeWidth = 3;

chart.data = data;

}); // end am4core.ready()
</script>
</p>
<!-- HTML -->
<div id="chartdiv"></div>
<!-- Copyright 2020 荒屋敷智也のブログ-->

コードの貼り付け

f:id:zenryokusyounen:20211029225841p:plain

利用規約

特にありません。
ご自由に改変等してご使用ください。

終わりに

  • 読者登録、ブックマークよろしくお願い致します。


|