<?xml version="1.0" encoding="UTF-8"?>
<window apply="demo.more.PolarWindRoseComposer">
<charts id="chart" type="column" polar="true"
title="Wind rose for South Shore Met Station, Oregon"
subtitle="Source: or.water.usgs.gov"/>
</window>
package demo.more;
import org.zkoss.chart.Charts;
import org.zkoss.chart.Legend;
import org.zkoss.chart.YAxis;
import org.zkoss.chart.model.CategoryModel;
import org.zkoss.chart.model.DefaultCategoryModel;
import org.zkoss.chart.plotOptions.SeriesPlotOptions;
import org.zkoss.zk.ui.select.SelectorComposer;
import org.zkoss.zk.ui.select.annotation.Wire;
import org.zkoss.zul.Window;
public class PolarWindRoseComposer extends SelectorComposer<Window> {
@Wire
Charts chart;
public void doAfterCompose(Window comp) throws Exception {
super.doAfterCompose(comp);
chart.getTitle().setAlign("left");
chart.getSubtitle().setAlign("left");
CategoryModel catemodel = new DefaultCategoryModel();
String[] series = PolarWindRoseData.getSeries();
String[] categories = PolarWindRoseData.getCategories();
Double[][] data = PolarWindRoseData.getData();
for (int i = 0; i < series.length; ++i) {
for (int j = 0; j < categories.length; ++j) {
catemodel.setValue(series[i], categories[j], data[j][i]);
}
}
chart.setModel(catemodel);
chart.getPane().setSize("85%");
Legend legend = chart.getLegend();
legend.setAlign("right");
legend.setVerticalAlign("top");
legend.setY(100);
legend.setLayout("vertical");
chart.getXAxis().setTickmarkPlacement("on");
YAxis yAxis = chart.getYAxis();
yAxis.setMin(0);
yAxis.setEndOnTick(false);
yAxis.setShowFirstLabel(true);
yAxis.setTitle("Frequency (%)");
yAxis.getLabels().setFormat("{value}%");
yAxis.setReversedStacks(false);
chart.getTooltip().setValueSuffix("%");
SeriesPlotOptions plotOptions = chart.getPlotOptions().getSeries();
plotOptions.setStacking("normal");
plotOptions.setShadow(false);
plotOptions.setPointPlacement("on");
plotOptions.setGroupPadding(0);
}
}
package demo.more;
public class PolarWindRoseData {
private static String[] series = { "< 0.5 m/s", "0.5-2 m/s", "2-4 m/s",
"4-6 m/s", "6-8 m/s", "8-10 m/s", "> 10 m/s" };
private static String[] categories = { "N", "NNE", "NE", "ENE", "E", "ESE",
"SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW" };
private static Double[][] data = {
{ 1.81, 1.78, 0.16, 0.00, 0.00, 0.00, 0.00, 3.75 },
{ 0.62, 1.09, 0.00, 0.00, 0.00, 0.00, 0.00, 1.71 },
{ 0.82, 0.82, 0.07, 0.00, 0.00, 0.00, 0.00, 1.71 },
{ 0.59, 1.22, 0.07, 0.00, 0.00, 0.00, 0.00, 1.88 },
{ 0.62, 2.20, 0.49, 0.00, 0.00, 0.00, 0.00, 3.32 },
{ 1.22, 2.01, 1.55, 0.30, 0.13, 0.00, 0.00, 5.20 },
{ 1.61, 3.06, 2.37, 2.14, 1.74, 0.39, 0.13, 11.4 },
{ 2.04, 3.42, 1.97, 0.86, 0.53, 0.49, 0.00, 9.31 },
{ 2.66, 4.74, 0.43, 0.00, 0.00, 0.00, 0.00, 7.83 },
{ 2.96, 4.14, 0.26, 0.00, 0.00, 0.00, 0.00, 7.37 },
{ 2.53, 4.01, 1.22, 0.49, 0.13, 0.00, 0.00, 8.39 },
{ 1.97, 2.66, 1.97, 0.79, 0.30, 0.00, 0.00, 7.70 },
{ 1.64, 1.71, 0.92, 1.45, 0.26, 0.10, 0.00, 6.09 },
{ 1.32, 2.40, 0.99, 1.61, 0.33, 0.00, 0.00, 6.64 },
{ 1.58, 4.28, 1.28, 0.76, 0.66, 0.69, 0.03, 9.28 },
{ 1.51, 5.00, 1.32, 0.13, 0.23, 0.13, 0.07, 8.39 } };
public static String[] getSeries() {
return series;
}
public static String[] getCategories() {
return categories;
}
public static Double[][] getData() {
return data;
}
}