Gwt-highcharts-pie-legends

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

GWTハイチャート-凡例付きの円グラフ

以下は、凡例付きの円グラフの例です。

link:/gwt_highcharts/gwt_highcharts_configuration_syntax [Highcharts構成構文]の章で、チャートを描画するために使用される構成をすでに確認しました。

凡例付きの円グラフの例を以下に示します。

構成

ここで、追加の構成/実行された手順を見てみましょう。

チャート

グラフタイプを「パイ」ベースに設定します。 chart.type は、チャートのシリーズタイプを決定します。 ここで、デフォルト値は「line」です。

chart.setType(Type.PIE);

plotOptions

*plotOptions.pie.showInLegend* 属性を使用して、円グラフに凡例を表示するようにplotOptionsを構成します。
chart.setPiePlotOptions(new PiePlotOptions()
   .setAllowPointSelect(true)
   .setCursor(Cursor.POINTER)
   .setPieDataLabels(new PieDataLabels()
      .setEnabled(false)
   )
   .setShowInLegend(true)
)

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

import org.moxieapps.gwt.highcharts.client.Chart;
import org.moxieapps.gwt.highcharts.client.Legend;
import org.moxieapps.gwt.highcharts.client.Point;
import org.moxieapps.gwt.highcharts.client.Series.Type;
import org.moxieapps.gwt.highcharts.client.Style;

import org.moxieapps.gwt.highcharts.client.ToolTip;
import org.moxieapps.gwt.highcharts.client.ToolTipData;
import org.moxieapps.gwt.highcharts.client.ToolTipFormatter;

import org.moxieapps.gwt.highcharts.client.labels.DataLabels;
import org.moxieapps.gwt.highcharts.client.labels.DataLabelsData;
import org.moxieapps.gwt.highcharts.client.labels.DataLabelsFormatter;
import org.moxieapps.gwt.highcharts.client.labels.PieDataLabels;
import org.moxieapps.gwt.highcharts.client.labels.Labels.Align;
import org.moxieapps.gwt.highcharts.client.labels.XAxisLabels;

import org.moxieapps.gwt.highcharts.client.plotOptions.ColumnRangePlotOptions;
import org.moxieapps.gwt.highcharts.client.plotOptions.PiePlotOptions;
import org.moxieapps.gwt.highcharts.client.plotOptions.PlotOptions.Cursor;

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

public class HelloWorld implements EntryPoint {
   public void onModuleLoad() {
      final Chart chart = new Chart()
         .setType(Type.PIE)
         .setChartTitleText("Browser market shares at a specific website, 2010")
         .setPlotBackgroundColor((String)null)
         .setPlotBorderWidth(null)
         .setPlotShadow(false)
         .setPiePlotOptions(new PiePlotOptions()
            .setAllowPointSelect(true)
            .setCursor(Cursor.POINTER)
            .setPieDataLabels(new PieDataLabels()
               .setEnabled(false)
            )
            .setShowInLegend(true)
         )
         .setToolTip(new ToolTip()
            .setFormatter(new ToolTipFormatter() {
               @Override
               public String format(ToolTipData toolTipData) {
                  return "<b>" + toolTipData.getPointName() + "</b>: " + toolTipData.getYAsDouble() + " %";
               }
            })
         );

         chart.addSeries(chart.createSeries()
            .setName("Browser share")
            .setPoints(new Point[]{
               new Point("Firefox", 45.0),
               new Point("IE", 26.8),
               new Point("Chrome", 12.8)
                  .setSliced(true)
                  .setSelected(true),
               new Point("Safari", 8.5),
               new Point("Opera", 6.2),
               new Point("Others", 0.7)
            })
         );
      RootPanel.get().add(chart);
   }
}

結果

結果を確認します。

凡例付きの円グラフ