LoginSignup
4
4

More than 5 years have passed since last update.

Googleのチャート機能をSenchaTouchの中に実装

Last updated at Posted at 2016-04-14

「SenchaTouch + GoogleCharts」を利用し、ローソク足チャートの実装をメモする。

GoogleChartsを読み込む

    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
      google.load("visualization", "1", {packages:["corechart"]});
    </script>

SenchaTouch側のPanelを準備する

SenchaTouch
{
    xtype: 'panel',
    html: [
        '<div class="tab_rate_chart_area_top">',
            '<div id="id-rate-chart-div"></div>',
        '</div>'
    ].join('')
}

GoogleChartsを初期化する

    // チャートを描画する
    drawChart: function(records){
        var chartId = 'id-rate-chart-div';
        var width = Ext.get(chartId).getWidth();
        var data = google.visualization.arrayToDataTable(records, true);
        var options = {
            legend: 'none',
            colors: ['#ccc'],
            chartArea: {
                left: 50,
                top: 15,
                width: width - 60,
                height: 130
            },
            hAxis: {
                showTextEvery: 6,
                textStyle: {
                    fontSize: 9
                }
            },
            vAxis: {
                textStyle: {
                    fontSize: 9
                }
            },
            candlestick:{
                hollowIsRising: true,
                fallingColor: {
                    fill: '#002DB2',
                    stroke: '#002DB2',
                    strokeWidth: '0'
                },
                risingColor:{
                    fill: '#B20000',
                    stroke: '#B20000',
                    strokeWidth: '0'
                }
            }
        };
        if (!this.chart) this.chart = new google.visualization.CandlestickChart(document.getElementById(chartId));
        this.chart.clearChart();
        if (records.length > 0) this.chart.draw(data, options);
    },
records = [
    ['ラベル', '最小値', '開始値', '終了値', '最大値'],
    ['ラベル', '最小値', '開始値', '終了値', '最大値']
]

実装済みアプリ

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