您可以使用 GWT-API 创建圆环图,您必须像这样为 PieChartOptions 编写 Wrapper
PieOpt.java
import com.google.gwt.core.client.JsArray;
import com.googlecode.gwt.charts.client.corechart.PieChartOptions;
import com.googlecode.gwt.charts.client.corechart.PieChartTooltip;
import com.googlecode.gwt.charts.client.options.BackgroundColor;
import com.googlecode.gwt.charts.client.options.ChartArea;
import com.googlecode.gwt.charts.client.options.Legend;
import com.googlecode.gwt.charts.client.options.PieSliceText;
import com.googlecode.gwt.charts.client.options.Slice;
import com.googlecode.gwt.charts.client.options.TextStyle;
public class PieOpt {
private PieChartOptions _this;
private PieOpt() {
_this = PieChartOptions.create();
}
public static PieOpt newInstance() {
return new PieOpt();
}
public PieChartOptions get() {
return _this;
}
public final void setBackgroundColor(BackgroundColor backgroundColor) {
_this.setBackgroundColor(backgroundColor);
}
public final void setBackgroundColor(String color) {
_this.setBackgroundColor(color);
}
public final void setChartArea(ChartArea chartArea) {
_this.setChartArea(chartArea);
}
public final void setColors(String... colors) {
_this.setColors(colors);
}
public final void setFontName(String name) {
_this.setFontName(name);
}
public final void setFontSize(double size) {
_this.setFontSize(size);
}
public final void setIs3D(boolean is3D) {
_this.setIs3D(is3D);
}
public final void setLegend(Legend legend) {
_this.setLegend(legend);
}
public final void setPieResidueSliceColor(String pieResidueSliceColor) {
_this.setPieResidueSliceColor(pieResidueSliceColor);
}
public final void setPieResidueSliceLabel(String pieResidueSliceLabel) {
_this.setPieResidueSliceLabel(pieResidueSliceLabel);
}
public final void setPieSliceBorderColor(String pieSliceBorderColor) {
_this.setPieSliceBorderColor(pieSliceBorderColor);
}
public final void setPieSliceText(PieSliceText pieSliceText) {
_this.setPieSliceText(pieSliceText);
}
public final void setPieSliceTextStyle(TextStyle pieSliceTextStyle) {
_this.setPieSliceTextStyle(pieSliceTextStyle);
}
public final void setReverseCategories(boolean reverseCategories) {
_this.setReverseCategories(reverseCategories);
}
public final void setSlices(JsArray<Slice> slices) {
_this.setSlices(slices);
}
public final void setSliceVisibilityThreshold(
double sliceVisibilityThreshold) {
_this.setSliceVisibilityThreshold(sliceVisibilityThreshold);
}
public final void setTitle(String title) {
_this.setTitle(title);
}
public final void setTitleTextStyle(TextStyle textStyle) {
_this.setTitleTextStyle(textStyle);
}
public final void setTooltip(PieChartTooltip tooltip) {
_this.setTooltip(tooltip);
}
public void setHole(double d) {
setHole(get(), d);
}
private final native void setHole(PieChartOptions chartOptions, double d) /*-{
chartOptions.pieHole = d;
}-*/;
}
并像这样使用它
ChartLoader chartLoader = new ChartLoader(ChartPackage.CORECHART);
chartLoader.loadApi(new Runnable() {
@Override
public void run() {
pieChart = new PieChart();
DataTable dataTable = DataTable.create();
dataTable.addColumn(ColumnType.STRING, "Name");
dataTable.addColumn(ColumnType.NUMBER, "Donuts eaten");
dataTable.addRows(4);
dataTable.setValue(0, 0, "Michael");
dataTable.setValue(1, 0, "Elisa");
dataTable.setValue(2, 0, "Robert");
dataTable.setValue(3, 0, "John");
dataTable.setValue(0, 1, 5);
dataTable.setValue(1, 1, 7);
dataTable.setValue(2, 1, 3);
dataTable.setValue(3, 1, 2);
PieOpt opt = PieOpt.newInstance();
opt.setHole(0.4);
pieChart.draw(dataTable, opt.get());
}
});
你完成了。