(ExtJS6.5)チャート
今回はチャートの改善点です。
チャートはclassic、modernどちらも共通のパッケージを使用しています。そのため、classicでも恩恵に預かれます。
キャプション
captionsコンフィグを使って、チャートのタイトル・サブタイトル・クレジットを簡単に設定できるようになりました。
Ext.define('Sample.view.main.Main', { extend: 'Ext.Panel', xtype: 'app-main', requires: [ 'Ext.chart.CartesianChart', 'Ext.chart.axis.Numeric', 'Ext.chart.axis.Time', 'Ext.chart.series.Line' ], layout: 'fit', bodyPadding: 20, items: { xtype: 'cartesian', insetPadding: 20, innerPadding: '0 20 0 0', store: 'USDJPY', captions: { title: 'ドル・円推移', subtitle: { text: '2012~2013年あたりの終値の推移', style: { color: '#0000aa' } }, credits: 'データ配信元: http://www.central-tanshifx.com/market/finder/popn-csv-download.html' }, axes: [ { type: 'numeric', position: 'left', fields: ['end'] }, { type: 'time', position: 'bottom', fields: ['date'], dateFormat: 'Y/m/d' } ], series: [ { type: 'line', xField: 'date', yField: 'end' } ] } });
ナビゲータ
チャート全体を表すミニマップを設置し、描画する範囲や位置を切り替えることができるようになりました。
Ext.define('Sample.view.main.Main', { extend: 'Ext.Panel', xtype: 'app-main', requires: [ 'Ext.chart.CartesianChart', 'Ext.chart.axis.Numeric', 'Ext.chart.axis.Time', 'Ext.chart.series.Line', 'Ext.chart.navigator.Container' ], layout: 'fit', bodyPadding: 20, items: { xtype: 'chartnavigator', reference: 'chartnavigator', navigator: { axis: 'bottom' }, chart: { xtype: 'cartesian', reference: 'chart', insetPadding: 20, innerPadding: '0 20 0 0', store: 'USDJPY', captions: { title: 'ドル・円推移' }, axes: [ { type: 'numeric', position: 'left', fields: ['end'] }, { id: 'bottom', type: 'time', position: 'bottom', fields: ['date'], dateFormat: 'Y/m/d' } ], series: [ { type: 'line', xField: 'date', yField: 'end' } ] } } });
画面下のほうに表示されているのがナビゲータ部分です。背景が白色の四角で囲われた部分を移動したり、拡大・縮小したりして操作できます。
x軸に、id: 'bottom'を設定していますが、これはnavigatorコンフィグのaxis: 'bottom'と一致させないといけません。Ext.chart.navigator.Containerの処理で、軸の参照を取得できなくなりエラーが発生してしまいます。
Ext.chart.series.BoxPlot
新しいチャートが追加されました。複数のデータの分布を表現できるみたいです。
http://examples.sencha.com/extjs/6.5.0/examples/kitchensink/?modern#boxplot-nobel
見た目はローソク足に似ていますが、時系列のデータではなく、国ごとの比較や年齢ごとの比較といったカテゴリ別のデータの場合に使用します。
こんなチャートがあるということを頭の片隅に入れておいて、使えそうな場面で適宜引っ張り出せるようにしましょう。
Ext.chart.series.Lineのcurveコンフィグ
以前からスプライン曲線はありましたが、curveコンフィグを指定して点と点をどう結ぶかをもう少し細かく指定できるようになりました。
APIには、↓の種類が挙げられています。
curve: { type: 'linear' } curve: { type: 'cardinal, tension: 0.5 } curve: { type: 'natural' } curve: { type: 'step-after' }
step-afterを指定すると↓のように描画されます。