堆叠和分组柱状图



下面是堆叠和分组柱状图的一个示例。

我们已经看过 Highcharts 配置语法 章节中用于绘制图表时使用的配置了。现在让我们来看一下其他配置,还要看到我们在 **plotoptions** 中是如何添加堆叠属性的。

给出堆叠和分组柱状图的一个示例如下。

plotOptions

plotOptions 是每个系列类型配置对象的包装对象。每个系列的配置对象还可以针对系列数组中给出的每个系列项进行覆盖。目的是将每个系列的值堆叠在一起。目的是将每个系列的值堆叠在一起。

使用 plotOptions.column.stacking 来配置图表堆叠,将其配置为“normal”。可能的值为 null(它将禁用堆叠)、“normal”(按值堆叠)和“percent”(按百分比堆叠图表)。

chart.setColumnPlotOptions(new ColumnPlotOptions()  
   .setStacking(Stacking.NORMAL)  
); 

series

配置每个系列的堆叠以识别系列组。

chart.addSeries(chart.createSeries()  
   .setName("John")  
   .setPoints(new Number[] {5, 3, 4, 7, 2})  
   .setStack("male")  
);  

示例

HelloWorld.java

package com.tutorialspoint.client;

import org.moxieapps.gwt.highcharts.client.Chart;
import org.moxieapps.gwt.highcharts.client.Series.Type;
import org.moxieapps.gwt.highcharts.client.plotOptions.ColumnPlotOptions;
import org.moxieapps.gwt.highcharts.client.plotOptions.PlotOptions.Stacking;

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

public class HelloWorld implements EntryPoint {
   public void onModuleLoad() {
      final Chart chart = new Chart()  
         .setType(Type.COLUMN)  
         .setChartTitleText("Total fruit consumption, grouped by gender")  
         .setColumnPlotOptions(new ColumnPlotOptions()  
            .setStacking(Stacking.NORMAL)  
         ); 

      chart.getXAxis()  
         .setCategories("Apples", "Oranges", "Pears", "Grapes", "Bananas");  

      chart.getYAxis()  
         .setAllowDecimals(false)  
         .setMin(0)  
         .setAxisTitleText("Number of fruits");  

      chart.addSeries(chart.createSeries()  
         .setName("John")  
         .setPoints(new Number[] {5, 3, 4, 7, 2})  
         .setStack("male")  
      );  
      chart.addSeries(chart.createSeries()  
         .setName("Joe")  
         .setPoints(new Number[] {3, 4, 4, 2, 5})  
         .setStack("male")  
      );  
      chart.addSeries(chart.createSeries()  
         .setName("Jane")  
         .setPoints(new Number[] {2, 2, 3, 2, 1})  
         .setStack("female")  
      );  
      chart.addSeries(chart.createSeries()  
         .setName("Janet")  
         .setPoints(new Number[] {3, 0, 4, 4, 3})  
         .setStack("female")  
      );  
      RootPanel.get().add(chart);
   }
}

结果

验证结果。

Stacked and Grouped Column Chart
gwt_highcharts_column_charts.htm
广告
© . All rights reserved.