LoginSignup
3
3

More than 5 years have passed since last update.

Mithril.jsとC3.js(d3.jsベースのチャートライブラリ)を組み合わせて使う

Posted at

Mithril.js http://mithril.js.org/
C3.js : http://c3js.org

// 線チャートコンポーネント
var SequenceChart = {
  controller: function() {
    var ctrl;
    ctrl = this;

    ctrl.renderChart = function(data, element, isInit, context) {
      // 初期化されていないなら、チャートを初期化
      if(!isInit) {
        ctrl.initChart(element, data);
      }
    };

    ctrl.initChart = function(element, model) {
      var chart, options;
      options = {
        data: {
          columns: model
        }
      };
      options.bindto = element;

      chart = c3.generate(options);
    };
  },
  view: function(ctrl, model) {
    return m('div', {
      // config属性でチャートを出力
      config: ctrl.renderChart.bind(ctrl, model)
    });
  }
};
var model = [
  ['labelA', 10, 20, 30],
  ['labelB', 20, 30, 40]
]

m.mount(document.body, SequenceChart(model));
3
3
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
3
3