package demo.charts3d;
import java.util.LinkedList;
import java.util.List;
import org.zkoss.chart.Charts;
import org.zkoss.chart.ChartsEvents;
import org.zkoss.chart.Color;
import org.zkoss.chart.Point;
import org.zkoss.chart.RadialGradient;
import org.zkoss.chart.Series;
import org.zkoss.chart.XAxis;
import org.zkoss.chart.YAxis;
import org.zkoss.chart.ZAxis;
import org.zkoss.chart.options3D.BackPanel;
import org.zkoss.chart.options3D.BottomPanel;
import org.zkoss.chart.options3D.Frame3D;
import org.zkoss.chart.options3D.Options3D;
import org.zkoss.chart.options3D.SidePanel;
import org.zkoss.chart.plotOptions.ScatterPlotOptions;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.select.SelectorComposer;
import org.zkoss.zk.ui.select.annotation.Wire;
import org.zkoss.zul.Window;
public class Scatter3DComposer extends SelectorComposer<Window> {
@Wire
Charts chart;
public void doAfterCompose(Window comp) throws Exception {
super.doAfterCompose(comp);
chart.setMargin(100);
Options3D opt3d = chart.getOptions3D();
Frame3D frame = opt3d.getFrame();
BottomPanel bottom = frame.getBottom();
BackPanel back = frame.getBack();
SidePanel side = frame.getSide();
opt3d.setEnabled(true);
opt3d.setAlpha(10);
opt3d.setBeta(30);
opt3d.setDepth(250);
opt3d.setViewDistance(5);
opt3d.setFitToPlot(false);
bottom.setSize(1);
bottom.setColor("rgba(0,0,0,0.02)");
back.setSize(1);
back.setColor("rgba(0,0,0,0.04)");
side.setSize(1);
side.setColor("rgba(0,0,0,0.06)");
ScatterPlotOptions sot = chart.getPlotOptions().getScatter();
sot.setWidth(10);
sot.setHeight(10);
sot.setDepth(10);
YAxis y0 = new YAxis();
XAxis x0 = new XAxis();
ZAxis z0 = new ZAxis();
y0.setMin(0);
y0.setMax(10);
y0.setTitle("");
x0.setMin(0);
x0.setMax(10);
x0.setGridLineWidth(1);
z0.setMin(0);
z0.setMax(10);
z0.setShowFirstLabel(false);
chart.setYAxis(y0);
chart.setXAxis(x0);
chart.setZAxis(z0);
chart.getLegend().setEnabled(false);
initGradientColors();
initSeries();
}
private void initGradientColors() {
List<Color> gradientColors = new LinkedList<Color>();
String[][] colors = {{"#7cb5ec", "rgb(73,130,185)"},
{"#434348", "rgb(16,16,21)"}, {"#90ed7d", "rgb(93,186,74)"},
{"#f7a35c", "rgb(196,112,41)"}, {"#8085e9", "rgb(77,82,182)"},
{"#f15c80", "rgb(190,41,77)"}, {"#e4d354", "rgb(177,160,33)"},
{"#2b908f", "rgb(0,93,92)"}, {"#f45b5b", "rgb(193,40,40)"},
{"#91e8e1", "rgb(94,181,174)"}
};
for (String[] color: colors) {
RadialGradient radialGradient = new RadialGradient(0.4, 0.3, 0.5);
radialGradient.setStops(color[0], color[1]);
gradientColors.add(new Color(radialGradient));
}
chart.setColors(gradientColors);
}
private void initSeries() {
Series series = chart.getSeries();
series.setName("Data");
series.setColorByPoint(true);
series.getAccessibility().setExposeAsGroupOnly(true);
series.setData(Point.of(1, 6, 5), Point.of(8, 7, 9), Point.of(1, 3, 4),
Point.of(4, 6, 8), Point.of(5, 7, 7), Point.of(6, 9, 6),
Point.of(7, 0, 5), Point.of(2, 3, 3), Point.of(3, 9, 8),
Point.of(3, 6, 5), Point.of(4, 9, 4), Point.of(2, 3, 3),
Point.of(6, 9, 9), Point.of(0, 7, 0), Point.of(7, 7, 9),
Point.of(7, 2, 9), Point.of(0, 6, 2), Point.of(4, 6, 7),
Point.of(3, 7, 7), Point.of(0, 1, 7), Point.of(2, 8, 6),
Point.of(2, 3, 7), Point.of(6, 4, 8), Point.of(3, 5, 9),
Point.of(7, 9, 5), Point.of(3, 1, 7), Point.of(4, 4, 2),
Point.of(3, 6, 2), Point.of(3, 1, 6), Point.of(6, 8, 5),
Point.of(6, 6, 7), Point.of(4, 1, 1), Point.of(7, 2, 7),
Point.of(7, 7, 0), Point.of(8, 8, 9), Point.of(9, 4, 1),
Point.of(8, 3, 4), Point.of(9, 8, 9), Point.of(3, 5, 3),
Point.of(0, 2, 4), Point.of(6, 0, 2), Point.of(2, 1, 3),
Point.of(5, 8, 9), Point.of(2, 1, 1), Point.of(9, 7, 6),
Point.of(3, 0, 2), Point.of(9, 9, 0), Point.of(3, 4, 8),
Point.of(2, 6, 1), Point.of(8, 9, 2), Point.of(7, 6, 5),
Point.of(6, 3, 1), Point.of(9, 3, 1), Point.of(8, 9, 3),
Point.of(9, 1, 0), Point.of(3, 8, 7), Point.of(8, 0, 0),
Point.of(4, 9, 7), Point.of(8, 6, 2), Point.of(4, 3, 0),
Point.of(2, 3, 5), Point.of(9, 1, 4), Point.of(1, 1, 4),
Point.of(6, 0, 2), Point.of(6, 1, 6), Point.of(3, 8, 8),
Point.of(8, 8, 7), Point.of(5, 5, 0), Point.of(3, 9, 6),
Point.of(5, 4, 3), Point.of(6, 8, 3), Point.of(0, 1, 5),
Point.of(6, 7, 3), Point.of(8, 3, 2), Point.of(3, 8, 3),
Point.of(2, 1, 6), Point.of(4, 6, 7), Point.of(8, 9, 9),
Point.of(5, 4, 2), Point.of(6, 1, 3), Point.of(6, 9, 5),
Point.of(4, 8, 2), Point.of(9, 7, 4), Point.of(5, 4, 2),
Point.of(9, 6, 1), Point.of(2, 7, 3), Point.of(4, 5, 4),
Point.of(6, 8, 1), Point.of(3, 4, 0), Point.of(2, 2, 6),
Point.of(5, 1, 2), Point.of(9, 9, 7), Point.of(6, 9, 9),
Point.of(8, 4, 3), Point.of(4, 1, 7), Point.of(6, 2, 5),
Point.of(0, 4, 9), Point.of(3, 5, 9), Point.of(6, 9, 1),
Point.of(1, 9, 2));
}
}