- GWT Highcharts 教程
- GWT Highcharts - 首页
- GWT Highcharts - 概述
- 设置环境
- 配置语法
- GWT Highcharts - 线形图
- GWT Highcharts - 区域图
- GWT Highcharts - 条形图
- GWT Highcharts - 柱形图
- GWT Highcharts - 饼图
- GWT Highcharts - 散布图
- GWT Highcharts - 动态图表
- GWT Highcharts - 组合图
- GWT Highcharts - 3D 图表
- GWT Highcharts - 地图图表
- GWT Highcharts 的有用资源
- GWT Highcharts - 快速指南
- GWT Highcharts - 有用资源
- GWT Highcharts - 讨论
使用叠加百分比的柱形图
以下是一个使用百分比的叠加柱形图示例。
在 Highcharts 配置语法 章节中,我们已经看到了用于绘制图表的配置。现在,让我们查看额外的配置,以及如何在 plotoptions 中添加堆叠属性。
下面给出了一个使用百分比的叠加柱形图的示例。
plotOptions
plotOptions 是每个系列类型的配置对象的包装对象。每个系列的配置对象也可以在系列数组中指定的每个系列项目中进行覆盖。这是将每个系列的值相互叠加。这是将每个系列的值相互叠加。
使用 plotOptions.column.stacking 将图表堆叠配置为“percent”。可能的值为 null(禁用堆叠)、“normal”(按值堆叠)和“percent”(按百分比堆叠图表)。
chart.setColumnPlotOptions(new ColumnPlotOptions() .setStacking(Stacking.PERCENT) );
示例
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.ToolTip;
import org.moxieapps.gwt.highcharts.client.ToolTipData;
import org.moxieapps.gwt.highcharts.client.ToolTipFormatter;
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.PERCENT)
)
.setToolTip(new ToolTip()
.setFormatter(new ToolTipFormatter() {
@Override
public String format(ToolTipData toolTipData) {
return toolTipData.getSeriesName() + ": " + toolTipData.getYAsLong() +
" ("+ Math.round(toolTipData.getPercentage()) + "%)";
}
})
);
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})
);
chart.addSeries(chart.createSeries()
.setName("Joe")
.setPoints(new Number[] {3, 4, 4, 2, 5})
);
chart.addSeries(chart.createSeries()
.setName("Jane")
.setPoints(new Number[] {2, 2, 3, 2, 1})
);
chart.addSeries(chart.createSeries()
.setName("Janet")
.setPoints(new Number[] {3, 0, 4, 4, 3})
);
RootPanel.get().add(chart);
}
}
结果
验证结果。
gwt_highcharts_column_charts.htm
广告