com.janeluo.jfinalplus.render.chart.amchart.AmChartsRender Maven / Gradle / Ivy
/**
* Copyright (c) 2011-2013, kidzhou 周磊 ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.janeluo.jfinalplus.render.chart.amchart;
import com.janeluo.jfinalplus.kit.KeyLabel;
import com.jfinal.log.Log;
import com.jfinal.render.Render;
import com.jfinal.render.RenderException;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
public class AmChartsRender extends Render implements AmChartsConstans {
public static int globalHeight = 600;
public static int globalWidth = 400;
private static final String CONTENT_TYPE = "text/html;charset=" + getEncoding();
private Log logger = Log.getLog(AmChartsRender.class);
/** 数据源 */
private List> data;
/** 数据描述 */
private List series;
/** 饼图数据 */
private List pies;
/** 报表div的高度 */
private int height;
/** 报表div的宽度 */
private int width;
/** amcharts文件存放路径 */
private String path = PATH;
/** 报表flash存放路径 */
private String flashFile;
/** 报表settings配置文件存放的路径 */
private String settingsFile;
/** 报表页面的标题 */
private String title;
/** 报表数据字符串 */
private String chartXml;
/** 图形类型 */
private String type;
public AmChartsRender(String type, int height, int width, String flashFile, String settingsFile) {
this.type = type;
this.height = height;
this.width = width;
this.flashFile = flashFile;
this.settingsFile = settingsFile;
}
public static AmChartsRender pie(List pies, String flashFile, String settingsFile) {
AmChartsRender render = pie(pies, flashFile, settingsFile, 0, 0);
return render;
}
public static AmChartsRender pie(List pies, String flashFile, String settingsFile, int height, int width) {
AmChartsRender render = new AmChartsRender(PIE, height > 0 ? height : globalHeight, width > 0 ? width
: globalWidth, flashFile, settingsFile);
render.setPies(pies);
return render;
}
public static AmChartsRender graph(List> data, List series, String flashFile, String settingsFile) {
return graph(data, series, flashFile, settingsFile, 0, 0);
}
public static AmChartsRender graph(List> data, List series, String flashFile, String settingsFile,
int height, int width) {
AmChartsRender render = new AmChartsRender(GRAPH, height > 0 ? height : globalHeight, width > 0 ? width
: globalWidth, flashFile, settingsFile);
render.setData(data);
render.setSeries(series);
return render;
}
@Override
public void render() {
genChartXml();
StringBuffer chart = new StringBuffer();
chart.append(
""
+ "amCharts Example ")
.append("");
PrintWriter writer = null;
try {
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
response.setContentType(CONTENT_TYPE);
writer = response.getWriter();
logger.debug("chart: " + chart.toString());
writer.write(chart.toString());
writer.flush();
} catch (IOException e) {
throw new RenderException(e);
} finally {
if (writer != null) {
writer.close();
}
}
}
private void genChartXml() {
if (GRAPH.equals(type)) {
GraphChart multipleChart = new GraphChart();
multipleChart.setSeriesNames(series);
multipleChart.setValues(data);
chartXml = Creater.createMultipleChart(multipleChart);
} else if (PIE.equals(type)) {
PieChart pieChart = new PieChart();
pieChart.setPies(pies);
chartXml = Creater.createPieChart(pieChart);
}
}
public static int getGlobalHeight() {
return globalHeight;
}
public static void setGlobalHeight(int globalHeight) {
AmChartsRender.globalHeight = globalHeight;
}
public static int getGlobalWidth() {
return globalWidth;
}
public static void setGlobalWidth(int globalWidth) {
AmChartsRender.globalWidth = globalWidth;
}
public Log getLogger() {
return logger;
}
public void setLogger(Log logger) {
this.logger = logger;
}
public List> getData() {
return data;
}
public void setData(List> data) {
this.data = data;
}
public List getSeries() {
return series;
}
public void setSeries(List series) {
this.series = series;
}
public List getPies() {
return pies;
}
public void setPies(List pies) {
this.pies = pies;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public String getFlashFile() {
return flashFile;
}
public void setFlashFile(String flashFile) {
this.flashFile = flashFile;
}
public String getSettingsFile() {
return settingsFile;
}
public void setSettingsFile(String settingsFile) {
this.settingsFile = settingsFile;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getChartXml() {
return chartXml;
}
public void setChartXml(String chartXml) {
this.chartXml = chartXml;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy