<?xml version="1.0" encoding="UTF-8"?>
<zk>
<style>
/* Custom CSS for the tooltip */
.highcharts-tooltip {
caption {
font-size: 0.9em;
font-weight: 500;
padding: 0.5em 0;
border-bottom: 1px solid var(--highcharts-neutral-color-10);
text-align: left;
}
th {
font-weight: normal;
padding: 0.15em 0;
color: var(--highcharts-neutral-color-60);
}
td {
font-weight: 500;
padding: 0.15em 0 0.15em 2em;
text-align: right;
}
tr:first-child td,
tr:first-child th {
padding-top: 0.75em;
}
tr:last-child td,
tr:last-child th {
padding-bottom: 0.25em;
}
}
</style>
<window apply="demo.line.LineBasicComposer">
<charts id="chart" type="line" title="Application users last 24 hours" />
</window>
</zk>
package demo.line;
import org.zkoss.chart.Charts;
import org.zkoss.chart.DateTimeLabelFormat;
import org.zkoss.chart.Series;
import org.zkoss.chart.Tooltip;
import org.zkoss.chart.XAxis;
import org.zkoss.chart.plotOptions.SeriesPlotOptions;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.select.SelectorComposer;
import org.zkoss.zk.ui.select.annotation.Wire;
import org.zkoss.zul.Window;
public class LineBasicComposer extends SelectorComposer<Window> {
@Wire
Charts chart;
public void doAfterCompose(Window comp) throws Exception {
super.doAfterCompose(comp);
// Enable series-label features for this demo
Executions.getCurrent().setAttribute("charts.modules.seriesLabel", "true");
chart.setPlotBorderColor("var(--highcharts-neutral-color-10, #e6e6e6)");
chart.setPlotBorderWidth(1);
chart.setPlotBorderRadius(5);
chart.getTitle().setAlign("left");
chart.setSubtitle("All traffic sources combined");
chart.getYAxis().setTitle("Unique users");
XAxis xAxis = chart.getXAxis();
xAxis.setType("datetime");
xAxis.setCrosshair(true);
// Don't show the date
DateTimeLabelFormat day = new DateTimeLabelFormat();
day.setBoundary("%H:%M");
day.setMain("%H:%M");
xAxis.getDateTimeLabelFormats().setDay(day);
xAxis.setLineWidth(0);
xAxis.setTickLength(6);
xAxis.setTickColor("var(--highcharts-neutral-color-10, #e6e6e6)");
chart.getLegend().setEnabled(false);
Tooltip tooltip = chart.getTooltip();
tooltip.setShared(true);
tooltip.setHeaderFormat("<table>" +
"<caption>{point.x:%[HM]} → {(add point.x 3540000):%[HM]}</caption>");
tooltip.setPointFormat("<tr>" +
"<th>" +
"<svg width=\"20\" height=\"10\">" +
"<path d=\"M 5 5 L 13 5\" stroke=\"{series.color}\" stroke-width=\"5\" " +
"stroke-linecap=\"round\" />" +
"</svg> " +
"{series.name}" +
"</th>" +
"<td>{point.y}</td>" +
"</tr>");
tooltip.setFooterFormat("</table>");
tooltip.setUseHTML(true);
// Common options for all series
SeriesPlotOptions series = chart.getPlotOptions().getSeries();
// Omit the timestamp from each data point, and rely on each data point
// being one hour apart.
series.setPointInterval(3600000); // one hour
series.getMarker().setEnabled(false);
int[] index = new int[] {0};
LineBasicData.getData().forEach((k, v) -> {
Series s = chart.getSeries(index[0]++);
s.setName(k);
s.setData(v);
});
chart.getSeries(0).setColor("light-dark(#0097FF, #27A6FE)");
chart.getSeries(1).setColor("#8791BA");
chart.getSeries(1).setDashStyle("ShortDot");
}
}
package demo.line;
import java.util.LinkedHashMap;
import java.util.Map;
public class LineBasicData {
private static Map<String, Integer[]> data;
static {
data = new LinkedHashMap<>();
data.put("Users", new Integer[] {
990, 652, 965, 1048, 939, 1012, 2089, 3995, 4123, 4302,
5289, 6115, 7723, 8162, 10089, 7812, 4127, 3812, 4156, 3805,
2958, 1984, 1432, 1299
});
data.put("Average", new Integer[] {
865, 832, 775, 728, 779, 812, 989, 1095, 1623, 2102,
2289, 2315, 2412, 2662, 3089, 2812, 2427, 2112, 2356, 2305,
1858, 1084, 932, 899
});
}
public static Map<String, Integer[]> getData() {
return data;
}
}