Gwt-googlecharts-candlestick-basic

提供:Dev Guides
移動先:案内検索

GWT Googleチャート-基本的なCandleStick

以下は、基本的なCandleStickチャートの例です。

link:/gwt_googlecharts/gwt_googlecharts_configuration_syntax [Googleグラフの構成構文]の章で、グラフを描画するために使用される構成を見てきました。 次に、CandleStickチャートの例を見てみましょう。

構成

*CandlestickChart* クラスを使用して、基本的なCandleStickチャートを表示しました。
//Candlestick chart
CandlestickChart chart = new CandlestickChart();

*_HelloWorld.java_*
package com.finddevguides.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootPanel;

import com.googlecode.gwt.charts.client.ChartLoader;
import com.googlecode.gwt.charts.client.ChartPackage;
import com.googlecode.gwt.charts.client.ColumnType;
import com.googlecode.gwt.charts.client.DataTable;
import com.googlecode.gwt.charts.client.corechart.CandlestickChart;
import com.googlecode.gwt.charts.client.corechart.CandlestickChartOptions;
import com.googlecode.gwt.charts.client.options.BackgroundColor;
import com.googlecode.gwt.charts.client.options.Legend;
import com.googlecode.gwt.charts.client.options.LegendPosition;

public class HelloWorld implements EntryPoint {
   private CandlestickChart chart;

   private void initialize() {
      ChartLoader chartLoader = new ChartLoader(ChartPackage.CORECHART);
      chartLoader.loadApi(new Runnable() {
         public void run() {
           //Create and attach the chart
            chart = new CandlestickChart();
            RootPanel.get().add(chart);
            draw();
         }
      });
   }
   private void draw() {
      DataTable dataTable = DataTable.create();
      dataTable.addColumn(ColumnType.STRING, "Date");
      dataTable.addColumn(ColumnType.NUMBER, "A");
      dataTable.addColumn(ColumnType.NUMBER, "B");
      dataTable.addColumn(ColumnType.NUMBER, "C");
      dataTable.addColumn(ColumnType.NUMBER, "D");

      dataTable.addRow("Mon", 20, 28, 38, 45);
      dataTable.addRow("Tue", 31, 38, 55, 66);
      dataTable.addRow("Wed", 50, 55, 77, 80);
      dataTable.addRow("Thu", 77, 77, 66, 50);
      dataTable.addRow("Fri", 68, 66, 22, 15);

     //Set options
      CandlestickChartOptions options = CandlestickChartOptions.create();
      options.setLegend(Legend.create(LegendPosition.NONE));

     //Draw the chart
      chart.draw(dataTable,options);
      chart.setWidth("400px");
      chart.setHeight("400px");
   }
   public void onModuleLoad() {
      initialize();
   }
}

結果

結果を確認します。

基本的なCandleStickチャート