-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Sorry for confusion, I am newbie in ZK... I create Highchart on my page with wrapper. Can I get html(svg) contents of this chart on server side, despite it rendered on client by svg engine ? I need to generate a report on server side, including chart, rendered on client side.
//----------------------This is wrapper class--------------------------//
package org.morphos.zkext.components.highcharts;
import org.morphos.zkext.components.highcharts.events.HChartClickEvent; import org.morphos.zkext.components.highcharts.events.HChartEvents; import org.zkoss.zk.au.out.AuInvoke; import org.zkoss.zk.ui.Desktop; import org.zkoss.zk.ui.Page; import org.zkoss.zk.ui.event.Events; import org.zkoss.zul.impl.XulElement;
import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Arrays; import java.util.List;
/** * ZK wrapper for HighCharts component. */ public class HChart extends XulElement implements IMapConverter {
static {
Util.init();
addClientEvent(HChart.class, HChartEvents.ON_CLICK, CE_IMPORTANT);
}
private static final long serialVersionUID = 1L;
private static final String GLOBAL_SETTINGS = HChart.class.getName() + ".global";
public static class ChartSettings extends Options {
public final ChartOptions chart = new ChartOptions();
public final List<String> colors = new ArrayList<String>();
public final CreditsOptions credits = new CreditsOptions();
public final ExportingOptions exporting = new ExportingOptions();
public final LegendOptions legend = new LegendOptions();
public final LoadingOptions loading = new LoadingOptions();
public final NavigationOptions navigation = new NavigationOptions();
public final PaneOptions pane = new PaneOptions();
public final PlotOptions plotOptions = null;
public final List<Series> series = new ArrayList<Series>();
public final TitleOptions subtitle = new TitleOptions();
public final TitleOptions title = new TitleOptions();
public final TooltipOptions tooltip = new TooltipOptions();
public final List<Axis> xAxis = new ArrayList<Axis>();
public final List<Axis> yAxis = new ArrayList<Axis>();
}
public final ChartSettings options = new ChartSettings();
private boolean _running;
public HChart() {
super();
addXAxis();
addYAxis();
setType(PlotType.LINE);
}
public void setDefaultColors(String... colors) {
options.colors.clear();
if (colors != null) {
options.colors.addAll(Arrays.asList(colors));
}
}
public String getType() {
return options.chart.type;
}
public void setType(PlotType type) {
try {
Field field = ChartSettings.class.getField("plotOptions");
field.setAccessible(true);
PlotOptions plotOptions = Util.getPlotType(type.getValue());
plotOptions.type = type.getValue();
field.set(options, plotOptions);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
options.chart.type = type.getValue();
options.series.clear();
}
public Axis getXAxis() {
return options.xAxis.isEmpty() ? null : options.xAxis.get(0);
}
public Axis getYAxis() {
return options.yAxis.isEmpty() ? null : options.yAxis.get(0);
}
public Series addSeries() {
return addSeries(PlotType.valueOf(options.chart.type));
}
public Series addSeries(PlotType type) {
Series series = new Series(type.getValue());
options.series.add(series);
return series;
}
public Axis addXAxis() {
return new Axis(options.xAxis);
}
public Axis addYAxis() {
return new Axis(options.yAxis);
}
public void run() {
init();
invoke("_run", toMap());
_running = true;
}
public boolean isRunning() {
return _running;
}
public void clear() {
_running = false;
options.series.clear();
invoke("_clear", null);
}
public void redraw() {
if (_running) {
invoke("_redraw", null);
} else {
run();
}
}
private void init() {
if (shouldInitialize()) {
invoke("_init", new GlobalSettings().toMap());
}
}
private boolean shouldInitialize() {
Desktop dt = getDesktop();
if (dt != null && !dt.hasAttribute(GLOBAL_SETTINGS)) {
dt.setAttribute(GLOBAL_SETTINGS, true);
return true;
}
return false;
}
@Override
public OptionsMap toMap() {
options.chart.renderTo = getUuid();
return options.toMap();
}
public String getTitle() {
return options.title.text;
}
public void setTitle(String text) {
options.title.text = text;
updateTitle();
}
public String getSubtitle() {
return options.subtitle.text;
}
public void setSubtitle(String text) {
options.subtitle.text = text;
updateTitle();
}
public void export() {
ensureRunning("Exporting");
invokeJS("_export", options.exporting.buttons_exportButton.onclick);
}
public void print() {
ensureRunning("Printing");
invokeJS("_print", options.exporting.buttons_printButton.onclick);
}
private void invokeJS(String func, String js) {
invoke(func, Util.toJS(js));
}
private void invoke(String func, Object arg) {
response(new AuInvoke(this, func, arg));
}
private void updateTitle() {
if (_running) {
OptionsMap map = new OptionsMap();
map.put("title", options.title);
map.put("subtitle", options.subtitle);
invoke("_title", map);
}
}
private void ensureRunning(String operation) {
if (!_running) {
throw new RuntimeException(operation + " requires an active chart.");
}
}
@Override
public String getWidgetClass() {
return "morphosext.Hchart";
}
@Override
public void onPageDetached(Page page) {
_running = false;
super.onPageDetached(page);
}
@Override
public void service(org.zkoss.zk.au.AuRequest request, boolean everError) {
final String cmd = request.getCommand();
if (cmd.equals(HChartEvents.ON_CLICK)) {
HChartClickEvent event = HChartClickEvent.getHChartClickEvent(request);
//Events.postEvent(HChartEvents.ON_CLICK, this, event);
Events.postEvent(event);
} else
super.service(request, everError);
}
}
Asked: 2017-04-11 13:27:16 +0800
Seen: 21 times
Last updated: Apr 11 '17
composite component help [closed]
EL in a forEach @command not working?
Different template for each grid row
Cardlayout animation is broken
Grid RowRender slow using 6.5.1 and sizable=true
setVisible(false), component will load or not
Decimalbox and doublebox value rounded on iPad
history management with page status