Gwt-highcharts-spline-inverted

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

GWTハイチャート-軸が反転したスプライン

このチャートを描画するために使用される構成は、リンク:/gwt_highcharts/gwt_highcharts_configuration_syntax [Highcharts構成構文]の章ですでに見ています。 ここで、逆軸を持つスプラインをさらに理解するために、次の例を考えてみましょう。

構成

グラフタイプをスプラインベースに設定します。 chart.typeは、チャートのシリーズタイプを決定します。 ここで、デフォルト値は「line」です。 反転する軸を構成します。 真のx軸が垂直で、y軸が水平の場合-チャートに棒シリーズが存在する場合、同じものが反転します。 ここで、デフォルト値はfalseです。

chart.setType(Series.Type.SPLINE)
.setInverted(true)

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

import org.moxieapps.gwt.highcharts.client.Chart;
import org.moxieapps.gwt.highcharts.client.Color;
import org.moxieapps.gwt.highcharts.client.Legend;
import org.moxieapps.gwt.highcharts.client.Series;
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.AxisLabelsData;
import org.moxieapps.gwt.highcharts.client.labels.AxisLabelsFormatter;
import org.moxieapps.gwt.highcharts.client.labels.XAxisLabels;
import org.moxieapps.gwt.highcharts.client.labels.YAxisLabels;

import org.moxieapps.gwt.highcharts.client.plotOptions.AreaPlotOptions;
import org.moxieapps.gwt.highcharts.client.plotOptions.Marker;

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

public class HelloWorld implements EntryPoint {
   public void onModuleLoad() {
      Chart chart = new Chart()
         .setType(Series.Type.SPLINE)
         .setInverted(true)
         .setChartTitleText("Atmosphere Temperature by Altitude")
         .setChartSubtitleText("According to the Standard Atmosphere Model")
         .setLegend(new Legend()
         .setEnabled(false))
         .setToolTip(new ToolTip()
            .setFormatter(new ToolTipFormatter() {
               @Override
               public String format(ToolTipData toolTipData) {
                  return toolTipData.getXAsLong() + " km: " + toolTipData.getYAsDouble() + "°C";
               }
            })
         )
         .setLegend(new Legend()
            .setEnabled(false)
         )
         .setAreaPlotOptions(new AreaPlotOptions()
            .setFillColor(new Color()
               .setLinearGradient(0, 0, 0, 1)
               .addColorStop(0, 69, 114, 167)
               .addColorStop(1, 2, 0, 0, 0)
            )
            .setMarker(new Marker()
               .setEnabled(false)
               .setHoverState(new Marker()
                  .setEnabled(true)
                  .setRadius(5)
               )
            )
            .setShadow(false)
            .setHoverStateLineWidth(1)
         );

      chart.getXAxis()
         .setReversed(false)
         .setAxisTitleText("Altitude")
         .setMaxPadding(0.05)
         .setShowLastLabel(true)
         .setLabels(new XAxisLabels()
            .setFormatter(new AxisLabelsFormatter() {
               @Override
               public String format(AxisLabelsData axisLabelsData) {
                  return axisLabelsData.getValueAsLong() + "km";
               }
            })
         );

      chart.getYAxis()
         .setAxisTitleText("Temperature")
         .setLineWidth(2)
         .setLabels(new YAxisLabels()
            .setFormatter(new AxisLabelsFormatter() {
               @Override
               public String format(AxisLabelsData axisLabelsData) {
                  return axisLabelsData.getValueAsLong() + "°";
               }
            })
         );

      chart.addSeries(chart.createSeries()
         .setName("Temperature")
         .setPoints(new Number[][]{
            {0, 15}, {10, -50}, {20, -56.5}, {30, -46.5}, {40, -22.1},
            {50, -2.5}, {60, -27.7}, {70, -55.7}, {80, -76.5}
         })
      );
      RootPanel.get().add(chart);
   }
}

結果

結果を確認します。

軸が反転したスプライン