<?xml version="1.0" encoding="UTF-8"?>
<window apply="demo.area.AreaBasicComposer">
<charts id="chart" type="area" title="US and USSR nuclear stockpiles" />
</window>
package demo.area;
import org.zkoss.chart.XAxis;
import org.zkoss.chart.YAxis;
import org.zkoss.json.JavaScriptValue;
import org.zkoss.zk.ui.select.SelectorComposer;
import org.zkoss.zk.ui.select.annotation.Wire;
import org.zkoss.zul.Window;
import org.zkoss.chart.Charts;
import org.zkoss.chart.Marker;
import org.zkoss.chart.Series;
import org.zkoss.chart.plotOptions.AreaPlotOptions;
public class AreaBasicComposer extends SelectorComposer<Window> {
@Wire
Charts chart;
public void doAfterCompose(Window comp) throws Exception {
super.doAfterCompose(comp);
chart.getAccessibility().setDescription("Image description: An area chart compares the nuclear stockpiles of the USA and the USSR/Russia between 1945 and 2017. The number of nuclear weapons is plotted on the Y-axis and the years on the X-axis. The chart is interactive, and the year-on-year stockpile levels can be traced for each country. The US has a stockpile of 6 nuclear weapons at the dawn of the nuclear age in 1945. This number has gradually increased to 369 by 1950 when the USSR enters the arms race with 6 weapons. At this point, the US starts to rapidly build its stockpile culminating in 32,040 warheads by 1966 compared to the USSR’s 7,089. From this peak in 1966, the US stockpile gradually decreases as the USSR’s stockpile expands. By 1978 the USSR has closed the nuclear gap at 25,393. The USSR stockpile continues to grow until it reaches a peak of 45,000 in 1986 compared to the US arsenal of 24,401. From 1986, the nuclear stockpiles of both countries start to fall. By 2000, the numbers have fallen to 10,577 and 21,000 for the US and Russia, respectively. The decreases continue until 2017 at which point the US holds 4,018 weapons compared to Russia’s 4,500.");
chart.setSubtitle("Source: <a href=\"https://fas.org/issues/nuclear-weapons/status-world-nuclear-forces/\" " +
"target=\"_blank\">FAS</a>");
XAxis xAxis = chart.getXAxis();
xAxis.setAllowDecimals(false);
xAxis.getLabels().setFormat("{value}");// clean, unformatted number for year
xAxis.getAccessibility().setRangeDescription("Range: 1940 to 2017.");
YAxis yAxis = chart.getYAxis();
yAxis.setTitle("Nuclear weapon states");
yAxis.getLabels().setFormatter(new JavaScriptValue("function () { return this.value / 1000 + 'k'; }"));
chart.getTooltip()
.setPointFormat("{series.name} had stockpiled <b>{point.y:,.0f}</b><br/>warheads in {point.x}");
AreaPlotOptions plotOptions = chart.getPlotOptions().getArea();
plotOptions.setPointStart(1940);
Marker marker = plotOptions.getMarker();
marker.setEnabled(false);
marker.setSymbol("circle");
marker.setRadius(2);
marker.getStates().getHover().setEnabled(true);
Series series1 = chart.getSeries();
series1.setName("USA");
series1.setData(AreaBasicData.getUSAData());
Series series2 = chart.getSeries(1);
series2.setName("USSR/Russia");
series2.setData(AreaBasicData.getUSSRData());
}
}
package demo.area;
public class AreaBasicData {
static public Integer[] getUSAData() {
return new Integer[] {
null, null, null, null, null, 2, 9, 13, 50, 170, 299, 438, 841,
1169, 1703, 2422, 3692, 5543, 7345, 12298, 18638, 22229, 25540,
28133, 29463, 31139, 31175, 31255, 29561, 27552, 26008, 25830,
26516, 27835, 28537, 27519, 25914, 25542, 24418, 24138, 24104,
23208, 22886, 23305, 23459, 23368, 23317, 23575, 23205, 22217,
21392, 19008, 13708, 11511, 10979, 10904, 11011, 10903, 10732,
10685, 10577, 10526, 10457, 10027, 8570, 8360, 7853, 5709, 5273,
5113, 5066, 4897, 4881, 4804, 4717, 4571, 4018, 3822, 3785, 3805,
3750, 3708, 3708
};
}
static public Integer[] getUSSRData() {
return new Integer[] {
null, null, null, null, null, null, null, null, null,
1, 5, 25, 50, 120, 150, 200, 426, 660, 863, 1048, 1627, 2492,
3346, 4259, 5242, 6144, 7091, 8400, 9490, 10671, 11736, 13279,
14600, 15878, 17286, 19235, 22165, 24281, 26169, 28258, 30665,
32146, 33486, 35130, 36825, 38582, 40159, 38107, 36538, 35078,
32980, 29154, 26734, 24403, 21339, 18179, 15942, 15442, 14368,
13188, 12188, 11152, 10114, 9076, 8038, 7000, 6643, 6286, 5929,
5527, 5215, 4858, 4750, 4650, 4600, 4500, 4490, 4300, 4350, 4330,
4310, 4495, 4477
};
}
}