8
4

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.

一人もくもく会にQiitaと同じタグチャートを作ってみる

Last updated at Posted at 2017-12-26

一人もくもく会 にそこそこ自分の記事が溜まってきたので、Qiitaと同じタグチャートを作ってみた。
Google Chart APIを使うだけ。

ちなみにQiitaのは下記。(丁度トレンドにいた方の)

Screenshot from 2017-12-26 22-56-39.png

Vueで。

<template>
  <div ref="chart"></div>
</template>

<script>
export default {
  props: ['tags'],

  mounted() {
    google.charts.load("current", { packages: ["corechart"] });
    google.charts.setOnLoadCallback(this.drawChart.bind(this));
  },

  methods: {
    drawChart() {
      const tags = this.tags.map(tag => {
        return [tag.tags.name, tag.cnt];
      });
      const data = new google.visualization.DataTable();
      data.addColumn("string", "Tag");
      data.addColumn("number", "Count");
      data.addRows(tags);
      const options = {
        width: 360,
        height: 256
      };
      const chart = new google.visualization.PieChart(this.$refs.chart);
      chart.draw(data, options);
    },
  }
};
</script>

呼び出し

<user-tag-chart :tags="<?= h(json_encode($tagSummary)) ?>"></user-tag-chart>

出来た。

20171224234434.png

すごく気持ち悪いのでQiitaと同じように(?)10位以下をまとめた。

20171224234434.png

成果が目に見えると気持ちが良い。

一人もくもく会

8
4
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
8
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?