📄 chart.java
字号:
/* Chart.java{{IS_NOTE Purpose: Description: History: Mon Jul 10 16:57:48 2006, Created by henrichen}}IS_NOTECopyright (C) 2006 Potix Corporation. All Rights Reserved.{{IS_RIGHT This program is distributed under GPL Version 2.0 in the hope that it will be useful, but WITHOUT ANY WARRANTY.}}IS_RIGHT*/package org.zkoss.zul;import org.zkoss.zk.ui.Component;import org.zkoss.zk.ui.Executions;import org.zkoss.zk.ui.UiException;import org.zkoss.zk.ui.event.Event;import org.zkoss.zk.ui.event.Events;import org.zkoss.zk.ui.event.EventListener;import org.zkoss.zul.impl.ChartEngine;import org.zkoss.zul.event.ChartDataEvent;import org.zkoss.zul.event.ChartDataListener;import org.zkoss.zul.event.ChartAreaListener;import org.zkoss.image.AImage;import org.zkoss.lang.Classes;import org.zkoss.lang.Objects;import org.zkoss.lang.Strings;import java.util.Date;import java.util.TimeZone;import java.io.ByteArrayOutputStream;import java.awt.image.BufferedImage;import java.awt.Paint;/** * The generic chart component. Developers set proper chart type, data model, * and the threeD (3D) attribute to draw proper chart. The model and type must * match to each other; or the result is unpredictable. The 3D chart is not supported * on all chart type. * * <table> * <tr><th>type</th><th>model</th><th>3D</th></tr> * <tr><td>pie</td><td>{@link PieModel}</td><td>o</td></tr> * <tr><td>ring</td><td>{@link PieModel}</td><td>x</td></tr> * <tr><td>bar</td><td>{@link CategoryModel}</td><td>o</td></tr> * <tr><td>line</td><td>{@link CategoryModel} or {@link XYModel}</td><td>o</td></tr> * <tr><td>area</td><td>{@link CategoryModel} or {@link XYModel}</td><td>x</td></tr> * <tr><td>stacked_bar</td><td>{@link CategoryModel}</td><td>o</td></tr> * <tr><td>stacked_area</td><td>{@link CategoryModel} or {@link XYModel}</td><td>x</td></tr> * <tr><td>waterfall</td><td>{@link CategoryModel}</td><td>x</td></tr> * <tr><td>polar</td><td>{@link XYModel}</td><td>x</td></tr> * <tr><td>scatter</td><td>{@link XYModel}</td><td>x</td></tr> * <tr><td>time_series</td><td>{@link XYModel}</td><td>x</td></tr> * <tr><td>polar</td><td>{@link XYModel}</td><td>x</td></tr> * <tr><td>step_area</td><td>{@link XYModel}</td><td>x</td></tr> * <tr><td>step</td><td>{@link XYModel}</td><td>x</td></tr> * </table> * * @author henrichen */public class Chart extends Imagemap { //chart type public static final String PIE = "pie"; public static final String RING = "ring"; public static final String BAR = "bar"; public static final String LINE = "line"; public static final String AREA = "area"; public static final String STACKED_BAR = "stacked_bar"; public static final String STACKED_AREA = "stacked_area"; public static final String WATERFALL = "waterfall"; public static final String POLAR = "polar"; public static final String SCATTER = "scatter"; public static final String TIME_SERIES = "time_series"; public static final String STEP = "step"; public static final String STEP_AREA = "step_area"; public static final String HISTOGRAM = "histogram"; public static final String CANDLESTICK = "candlestick"; public static final String HIGHLOW = "highlow"; //Time Series Chart Period public static final String YEAR = "year"; public static final String QUARTER = "quarter"; public static final String MONTH = "month"; public static final String WEEK = "week"; public static final String DAY = "day"; public static final String HOUR = "hour"; public static final String MINUTE = "minute"; public static final String SECOND = "second"; public static final String MILLISECOND = "millisecond"; //control variable private boolean _smartDrawChart; //whether post the smartDraw event already? private transient ChartDataListener _dataListener; private transient EventListener _smartDrawChartListener; //the smartDrawListner private String _type; //chart type (pie, ring, bar, line, xy, etc) private boolean _threeD; //whether a 3D chart //chart related attributes private String _title; //chart title private int _intWidth = 400; //default to 400 private int _intHeight = 200; //default to 200 private String _xAxis; private String _yAxis; private boolean _showLegend = true; // wether show legend private boolean _showTooltiptext = true; //wether show tooltiptext private String _orient = "vertical"; //orient private ChartAreaListener _areaListener; //callback function when chart area changed private String _paneColor; // pane's color private int[] _paneRGB; //pane red, green, blue (0 ~ 255, 0 ~ 255, 0 ~ 255) private int _paneAlpha = 255; //pane alpha transparency (0 ~ 255, default to 255) //plot related attributes private int _fgAlpha = 255; //foreground alpha transparency (0 ~ 255, default to 255) private String _bgColor; private int[] _bgRGB; //background red, green, blue (0 ~ 255, 0 ~ 255, 0 ~ 255) private int _bgAlpha = 255; //background alpha transparency (0 ~ 255, default to 255) //Time Series Chart related attributes private TimeZone _tzone; private String _period; //chart data model private ChartModel _model; //chart data model //chart engine private ChartEngine _engine; //chart engine. model and engine is related /** * Set the chart's type (Chart.PIE, Chart.BAR, Chart.LINE, etc.). */ public void setType(String type) { if (Objects.equals(_type, type)) { return; } _type = type; smartDrawChart(); } /** * Get the chart's type. */ public String getType() { return _type; } /** * Set true to show three dimensional graph (If a type of chart got no 3d peer, this is ignored). */ public void setThreeD(boolean b) { if (_threeD == b) { return; } _threeD = b; smartDrawChart(); } /** * Whether a 3d chart. */ public boolean isThreeD() { return _threeD; } /** * Set the chart's title. * @param title the chart's title. * */ public void setTitle(String title) { if (Objects.equals(_title, title)) { return; } _title = title; smartDrawChart(); } /** * Get the chart's title. */ public String getTitle() { return _title; } /** * Override super class to prepare the int width. */ public void setWidth(String w) { if (Objects.equals(w, getWidth())) { return; } _intWidth = stringToInt(w); super.setWidth(w); } /** * Get the chart int width in pixel; to be used by the derived subclass. */ public int getIntWidth() { return _intWidth; } /** * Override super class to prepare the int height. */ public void setHeight(String h) { if (Objects.equals(h, getHeight())) { return; } _intHeight = stringToInt(h); super.setHeight(h); } /** * Get the chart int width in pixel; to be used by the derived subclass. */ public int getIntHeight() { return _intHeight; } /** * Set the label in xAxis. * @param label label in xAxis. */ public void setXAxis(String label) { if (Objects.equals(_xAxis, label)) { return; } _xAxis = label; smartDrawChart(); } /** * Get the label in xAxis. */ public String getXAxis() { return _xAxis; } /** * Set the label in yAxis. * @param label label in yAxis. */ public void setYAxis(String label) { if (Objects.equals(_yAxis, label)) { return; } _yAxis = label; smartDrawChart(); } /** * Get the label in yAxis. */ public String getYAxis() { return _yAxis; } /** * whether show the chart's legend. * @param showLegend true if want to show the legend (default to true). */ public void setShowLegend(boolean showLegend) { if (_showLegend == showLegend) { return; } _showLegend = showLegend; smartDrawChart(); } /** * Check whether show the legend of the chart. */ public boolean isShowLegend() { return _showLegend; } /** * whether show the chart's tooltip. * @param showTooltiptext true if want to pop the tooltiptext (default to true). */ public void setShowTooltiptext(boolean showTooltiptext) { if (_showTooltiptext == showTooltiptext) { return; } _showTooltiptext = showTooltiptext; smartDrawChart(); } /** * Check whether show the tooltiptext. */ public boolean isShowTooltiptext() { return _showTooltiptext; } /** * Set the pane alpha (transparency, 0 ~ 255). * @param alpha the transparency of pane color (0 ~ 255, default to 255 opaque). */ public void setPaneAlpha(int alpha) { if (alpha == _paneAlpha) { return; } if (alpha > 255 || alpha < 0) { alpha = 255; } _paneAlpha = alpha; smartDrawChart(); } /** * Get the pane alpha (transparency, 0 ~ 255, opacue). */ public int getPaneAlpha() { return _paneAlpha; } /** * Set the pane color of the chart. * @param color in #RRGGBB format (hexdecimal). */ public void setPaneColor(String color) { if (Objects.equals(color, _paneColor)) { return; } _paneColor = color; if (_paneColor == null) { _paneRGB = null; } else { _paneRGB = new int[3]; decode(_paneColor, _paneRGB); } smartDrawChart(); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -