📄 simplechartengine.java
字号:
area.setAttribute("series", series);
if (chart.isShowTooltiptext() && info.getToolTipText() == null) {
area.setTooltiptext(series.toString());
}
} else if (model instanceof HiLoModel) {
Comparable series = ((HiLoModel)model).getSeries();
if (series == null) {
series = DEFAULT_HI_LO_SERIES;
}
area.setAttribute("series", series);
if (chart.isShowTooltiptext() && info.getToolTipText() == null) {
area.setTooltiptext(series.toString());
}
}
}
/**
* decode TickLabelEntity into key-value pair of Area's componentScope.
* @param area the Area where the final attribute is set
* @param info the TickLabelEntity to be decoded.
*/
private void decodeTickLabelInfo(Area area, TickLabelEntity info, Chart chart) {
if (info == null) {
return;
}
final ChartModel model = chart.getModel();
final int seq = ((Integer)chart.getAttribute("TICK_SEQ")).intValue();
if (model instanceof CategoryModel) {
Comparable category = ((CategoryModel)model).getCategory(seq);
area.setAttribute("category", category);
if (chart.isShowTooltiptext() && info.getToolTipText() == null) {
area.setTooltiptext(category.toString());
}
}
}
/**
* decode PieSectionEntity into key-value pair of Area's componentScope.
* @param area the Area where the final attribute is set
* @param info the PieSectionEntity to be decoded.
*/
private void decodePieInfo(Area area, PieSectionEntity info) {
if (info == null) {
return;
}
PieDataset dataset = info.getDataset();
Comparable category = info.getSectionKey();
area.setAttribute("category", category);
area.setAttribute("value", dataset.getValue(category));
}
/**
* decode CategoryItemEntity into key-value pair of Area's componentScope.
* @param area the Area where the final attribute is set
* @param info the CategoryItemEntity to be decoded.
*/
private void decodeCategoryInfo(Area area, CategoryItemEntity info) {
if (info == null) {
return;
}
CategoryDataset dataset = info.getDataset();
int si = info.getSeries();
Comparable category = (Comparable) info.getCategory();
Comparable series = (Comparable) dataset.getRowKey(si);
area.setAttribute("series", series);
area.setAttribute("category", category);
area.setAttribute("value", dataset.getValue(series, category));
}
/**
* decode XYItemEntity into key-value pair of Area's componentScope.
* @param area the Area where the final attribute is set
* @param info the XYItemEntity to be decoded.
*/
private void decodeXYInfo(Area area, XYItemEntity info) {
if (info == null) {
return;
}
XYDataset dataset = info.getDataset();
int si = info.getSeriesIndex();
int ii = info.getItem();
area.setAttribute("series", dataset.getSeriesKey(si));
if (dataset instanceof OHLCDataset) {
OHLCDataset ds = (OHLCDataset) dataset;
area.setAttribute("date", new Date(ds.getX(si, ii).longValue()));
area.setAttribute("open", ds.getOpen(si, ii));
area.setAttribute("high", ds.getHigh(si, ii));
area.setAttribute("low", ds.getLow(si, ii));
area.setAttribute("close", ds.getClose(si, ii));
area.setAttribute("volume", ds.getVolume(si, ii));
} else {
area.setAttribute("x", dataset.getX(si, ii));
area.setAttribute("y", dataset.getY(si, ii));
}
}
//-- Chart specific implementation --//
/** base chart */
abstract private class ChartImpl {
abstract void render(Chart chart, Area area, ChartEntity info);
abstract JFreeChart createChart(Chart chart);
}
/** pie chart */
private class Pie extends ChartImpl {
public void render(Chart chart, Area area, ChartEntity info) {
if (info instanceof LegendItemEntity) {
area.setAttribute("entity", "LEGEND");
Integer seq = (Integer)chart.getAttribute("LEGEND_SEQ");
seq = seq == null ? new Integer(0) : new Integer(seq.intValue()+1);
chart.setAttribute("LEGEND_SEQ", seq);
decodeLegendInfo(area, (LegendItemEntity)info, chart);
} else if (info instanceof PieSectionEntity) {
area.setAttribute("entity", "DATA");
decodePieInfo(area, (PieSectionEntity)info);
} else {
area.setAttribute("entity", "TITLE");
if (chart.isShowTooltiptext()) {
area.setTooltiptext(chart.getTitle());
}
}
}
protected PieDataset getDataset(ChartModel model) {
if (model instanceof CategoryModel) {
return CategoryModelToPieDataset((CategoryModel)model);
} else if (model instanceof PieModel) {
return PieModelToPieDataset((PieModel) model);
} else {
throw new UiException("model must be a org.zkoss.zul.PieModel or a org.zkoss.zul.CategoryModel");
}
}
public JFreeChart createChart(Chart chart) {
ChartModel model = (ChartModel) chart.getModel();
return ChartFactory.createPieChart(
chart.getTitle(),
getDataset(model),
chart.isShowLegend(),
chart.isShowTooltiptext(), true);
}
}
/** pie3d chart */
private class Pie3d extends Pie {
public JFreeChart createChart(Chart chart) {
ChartModel model = (ChartModel) chart.getModel();
return ChartFactory.createPieChart3D(
chart.getTitle(),
getDataset(model),
chart.isShowLegend(),
chart.isShowTooltiptext(), true);
}
}
/** ring chart */
private class Ring extends Pie {
public JFreeChart createChart(Chart chart) {
ChartModel model = (ChartModel) chart.getModel();
return ChartFactory.createRingChart(
chart.getTitle(),
getDataset(model),
chart.isShowLegend(),
chart.isShowTooltiptext(), true);
}
}
/** bar chart */
private class Bar extends ChartImpl {
public void render(Chart chart, Area area, ChartEntity info) {
if (info instanceof LegendItemEntity) {
area.setAttribute("entity", "LEGEND");
Integer seq = (Integer)chart.getAttribute("LEGEND_SEQ");
seq = seq == null ? new Integer(0) : new Integer(seq.intValue()+1);
chart.setAttribute("LEGEND_SEQ", seq);
decodeLegendInfo(area, (LegendItemEntity)info, chart);
} else if (info instanceof CategoryItemEntity) {
area.setAttribute("entity", "DATA");
decodeCategoryInfo(area, (CategoryItemEntity)info);
} else if (info instanceof XYItemEntity) {
area.setAttribute("entity", "DATA");
decodeXYInfo(area, (XYItemEntity) info);
} else if (info instanceof TickLabelEntity) {
area.setAttribute("entity", "CATEGORY");
Integer seq = (Integer)chart.getAttribute("TICK_SEQ");
seq = seq == null ? new Integer(0) : new Integer(seq.intValue()+1);
chart.setAttribute("TICK_SEQ", seq);
decodeTickLabelInfo(area, (TickLabelEntity) info, chart);
} else {
area.setAttribute("entity", "TITLE");
if (chart.isShowTooltiptext()) {
area.setTooltiptext(chart.getTitle());
}
}
}
public JFreeChart createChart(Chart chart) {
ChartModel model = (ChartModel) chart.getModel();
if (model instanceof CategoryModel) {
return ChartFactory.createBarChart(
chart.getTitle(),
chart.getXAxis(),
chart.getYAxis(),
CategoryModelToCategoryDataset((CategoryModel)model),
getOrientation(chart.getOrient()),
chart.isShowLegend(),
chart.isShowTooltiptext(), true);
} else if (model instanceof XYModel) {
return ChartFactory.createXYBarChart(
chart.getTitle(),
chart.getXAxis(),
false,
chart.getYAxis(),
(IntervalXYDataset) XYModelToXYDataset((XYModel)model),
getOrientation(chart.getOrient()),
chart.isShowLegend(),
chart.isShowTooltiptext(), true);
} else {
throw new UiException("model must be a org.zkoss.zul.CategoryModel or a org.zkoss.zul.XYModel");
}
}
}
/** bar3d chart */
private class Bar3d extends Bar {
public JFreeChart createChart(Chart chart) {
ChartModel model = (ChartModel) chart.getModel();
if (!(model instanceof CategoryModel)) {
throw new UiException("model must be a org.zkoss.zul.CategoryModel");
}
return ChartFactory.createBarChart3D(
chart.getTitle(),
chart.getXAxis(),
chart.getYAxis(),
CategoryModelToCategoryDataset((CategoryModel)model),
getOrientation(chart.getOrient()),
chart.isShowLegend(),
chart.isShowTooltiptext(), true);
}
}
/** area chart */
private class AreaImpl extends ChartImpl {
public void render(Chart chart, Area area, ChartEntity info) {
if (info instanceof LegendItemEntity) {
area.setAttribute("entity", "LEGEND");
Integer seq = (Integer)chart.getAttribute("LEGEND_SEQ");
seq = seq == null ? new Integer(0) : new Integer(seq.intValue()+1);
chart.setAttribute("LEGEND_SEQ", seq);
decodeLegendInfo(area, (LegendItemEntity)info, chart);
} else if (info instanceof CategoryItemEntity) {
area.setAttribute("entity", "DATA");
decodeCategoryInfo(area, (CategoryItemEntity)info);
} else if (info instanceof XYItemEntity) {
area.setAttribute("entity", "DATA");
decodeXYInfo(area, (XYItemEntity) info);
} else if (info instanceof TickLabelEntity) {
area.setAttribute("entity", "CATEGORY");
Integer seq = (Integer)chart.getAttribute("TICK_SEQ");
seq = seq == null ? new Integer(0) : new Integer(seq.intValue()+1);
chart.setAttribute("TICK_SEQ", seq);
decodeTickLabelInfo(area, (TickLabelEntity) info, chart);
} else {
area.setAttribute("entity", "TITLE");
if (chart.isShowTooltiptext()) {
area.setTooltiptext(chart.getTitle());
}
}
}
public JFreeChart createChart(Chart chart) {
ChartModel model = (ChartModel) chart.getModel();
if (model instanceof CategoryModel) {
return ChartFactory.createAreaChart(
chart.getTitle(),
chart.getXAxis(),
chart.getYAxis(),
CategoryModelToCategoryDataset((CategoryModel)model),
getOrientation(chart.getOrient()),
chart.isShowLegend(),
chart.isShowTooltiptext(), true);
} else if (model instanceof XYModel) {
return ChartFactory.createXYAreaChart(
chart.getTitle(),
chart.getXAxis(),
chart.getYAxis(),
XYModelToXYDataset((XYModel)model),
getOrientation(chart.getOrient()),
chart.isShowLegend(),
chart.isShowTooltiptext(), true);
} else {
throw new UiException("model must be a org.zkoss.zul.CategoryModel or a org.zkoss.zul.XYModel");
}
}
}
/** line chart */
private class Line extends ChartImpl {
public void render(Chart chart, Area area, ChartEntity info) {
if (info instanceof LegendItemEntity) {
area.setAttribute("entity", "LEGEND");
Integer seq = (Integer)chart.getAttribute("LEGEND_SEQ");
seq = seq == null ? new Integer(0) : new Integer(seq.intValue()+1);
chart.setAttribute("LEGEND_SEQ", seq);
decodeLegendInfo(area, (LegendItemEntity)info, chart);
} else if (info instanceof CategoryItemEntity) {
area.setAttribute("entity", "DATA");
decodeCategoryInfo(area, (CategoryItemEntity)info);
} else if (info instanceof XYItemEntity) {
area.setAttribute("entity", "DATA");
decodeXYInfo(area, (XYItemEntity) info);
} else if (info instanceof TickLabelEntity) {
area.setAttribute("entity", "CATEGORY");
Integer seq = (Integer)chart.getAttribute("TICK_SEQ");
seq = seq == null ? new Integer(0) : new Integer(seq.intValue()+1);
chart.setAttribute("TICK_SEQ", seq);
decodeTickLabelInfo(area, (TickLabelEntity) info, chart);
} else {
area.setAttribute("entity", "TITLE");
if (chart.isShowTooltiptext()) {
area.setTooltiptext(chart.getTitle());
}
}
}
public JFreeChart createChart(Chart chart) {
ChartModel model = (ChartModel) chart.getModel();
if (model instanceof CategoryModel) {
return ChartFactory.createLineChart(
chart.getTitle(),
chart.getXAxis(),
chart.getYAxis(),
CategoryModelToCategoryDataset((CategoryModel) model),
getOrientation(chart.getOrient()),
chart.isShowLegend(),
chart.isShowTooltiptext(), true);
} else if (model instanceof XYModel) {
return ChartFactory.createXYLineChart(
chart.getTitle(),
chart.getXAxis(),
chart.getYAxis(),
XYModelToXYDataset((XYModel) model),
getOrientation(chart.getOrient()),
chart.isShowLegend(),
chart.isShowTooltiptext(), true);
} else {
throw new UiException("model must be a org.zkoss.zul.CategoryModel or a org.zkoss.zul.XYModel");
}
}
}
/** line3d chart */
private class Line3d extends Line {
public JFreeChart createChart(Chart chart) {
ChartModel model = (ChartModel) chart.getModel();
if (!(model instanceof CategoryModel)) {
throw new UiException("model must be a org.zkoss.zul.CategoryModel");
}
return ChartFactory.createLineChart3D(
chart.getTitle(),
chart.getXAxis(),
chart.getYAxis(),
CategoryModelToCategoryDataset((CategoryModel) model),
getOrientation(chart.getOrient()),
chart.isShowLegend(),
chart.isShowTooltiptext(), true);
}
}
/** stackedbar chart */
private class StackedBar extends ChartImpl {
public void render(Chart chart, Area area, ChartEntity info) {
if (info instanceof LegendItemEntity) {
area.setAttribute("entity", "LEGEND");
Integer seq = (Integer)chart.getAttribute("LEGEND_SEQ");
seq = seq == null ? new Integer(0) : new Integer(seq.intValue()+1);
chart.setAttribute("LEGEND_SEQ", seq);
decodeLegendInfo(area, (LegendItemEntity)info, chart);
} else if (info instanceof CategoryItemEntity) {
area.setAttribute("entity", "DATA");
decodeCategoryInfo(area, (CategoryItemEntity)info);
} else if (info instanceof TickLabelEntity) {
area.setAttribute("entity", "CATEGORY");
Integer seq = (Integer)chart.getAttribute("TICK_SEQ");
seq = seq == null ? new Integer(0) : new Integer(seq.intValue()+1);
chart.setAttribute("TICK_SEQ", seq);
decodeTickLabelInfo(area, (TickLabelEntity) info, chart);
} else {
area.setAttribute("entity", "TITLE");
if (chart.isShowTooltiptext()) {
area.setTooltiptext(chart.getTitle());
}
}
}
public JFreeChart createChart(Chart chart) {
ChartModel model = (ChartModel) chart.getModel();
if (!(model instanceof CategoryModel)) {
throw new UiException("model must be a org.zkoss.zul.CategoryModel");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -