GWT Highcharts - Graphique à barres de base

Voici un exemple de graphique à barres.

Nous avons déjà vu les configurations utilisées pour dessiner un graphique dans le chapitre Syntaxe de configuration Highcharts . Voyons maintenant un exemple de graphique à barres de base. Nous comprendrons également la configuration supplémentaire. Nous avons changé l'attribut type dans le graphique.

graphique

Configurez le type de graphique pour qu'il soit basé sur une «barre». chart.typedécide du type de série du graphique. Ici, la valeur par défaut est "line".

chart.setType(Type.BAR);

Exemple

HelloWorld.java

package com.tutorialspoint.client;

import org.moxieapps.gwt.highcharts.client.AxisTitle;
import org.moxieapps.gwt.highcharts.client.Chart;
import org.moxieapps.gwt.highcharts.client.Credits;
import org.moxieapps.gwt.highcharts.client.Legend;
import org.moxieapps.gwt.highcharts.client.Series.Type;
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.plotOptions.BarPlotOptions;

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(Type.BAR)  
         .setChartTitleText("Historic World Population by Region")  
         .setChartSubtitleText("Source: Wikipedia.org")  
         .setBarPlotOptions(new BarPlotOptions()  
            .setDataLabels(new DataLabels()  
               .setEnabled(true)  
            )  
         )  
         .setLegend(new Legend()  
            .setLayout(Legend.Layout.VERTICAL)  
            .setAlign(Legend.Align.RIGHT)  
            .setVerticalAlign(Legend.VerticalAlign.TOP)  
            .setX(-100)  
            .setY(100)  
            .setFloating(true)  
            .setBorderWidth(1)  
            .setBackgroundColor("#FFFFFF")  
            .setShadow(true)  
         )  
         .setCredits(new Credits()  
            .setEnabled(false)  
         )  
         .setToolTip(new ToolTip()  
            .setFormatter(new ToolTipFormatter() {
               @Override
               public String format(ToolTipData toolTipData) {
                  return toolTipData.getSeriesName() + ": " + toolTipData.getYAsLong() +" million";  
               }
         }));
         chart.getXAxis()  
            .setCategories("Africa", "America", "Asia", "Europe", "Oceania");  
         chart.getYAxis()  
            .setAxisTitle(new AxisTitle()  
               .setText("Population (millions)")  
               .setAlign(AxisTitle.Align.HIGH)  
            );  
         chart.addSeries(chart.createSeries()  
            .setName("Year 1800")  
            .setPoints(new Number[] { 107, 31, 635, 203, 2 })  
         );  
         chart.addSeries(chart.createSeries()  
            .setName("Year 1900")  
            .setPoints(new Number[] { 133, 156, 947, 408, 6 })  
         );  
         chart.addSeries(chart.createSeries()  
            .setName("Year 2008")  
            .setPoints(new Number[] { 973, 914, 4054, 732, 34 })  
         );  
      RootPanel.get().add(chart);
   }
}

Résultat

Vérifiez le résultat.