open flash chart with struts2 pie

open flash chart with struts2 pie

connext-graphs是struts2的标签,是其可以应用ofc。通过controller控制数据来源,从而显示


open flash chart with struts2 pie 收藏
官网为:http://teethgrinder.co.uk/open-flash-chart/

在 http://www.connext.co.za/下载connext-graphs-0.6.jar (现在是最新版,源代码在https://connext-graphs.dev.java.net/source/browse/connext-graphs/ 用svn 下,不过你要先注册先,它会要求你输入注册名和密码的)

参照struts2-pluign

http://cwiki.apache.org/S2PLUGINS/connext-graph-plugin.html里的做法,把刚才下载的connext-graphs-0.6.jar 放到你的/WEB-INF/lib下,然后就是写action jsp (据说可以用在freemarker了,不过我没有试过)

我的action:

public class GraphAction extends ActionSupport {

private static final long serialVersionUID = -7553677081007831357L;
private String value;

@SuppressWarnings("unchecked")
@Override
public String execute() throws Exception {
OFCGraphController controller = new OFCGraphController();
controller.getTitle().setText("Example 01");
controller.getTitle().setSize(12);
PieLabels pieLabels = new PieLabels();
List<String> colours = new ArrayList<String>();
colours.add("#d01f3c");
colours.add("#356aa0");
colours.add("#C79810");
pieLabels.setColours(colours);
controller.setLabels(pieLabels);
controller.getLabels().setLabels(Arrays.asList(labels));
controller.getYLegend().setText("No. of tasks");
controller.getYLegend().setColor("#8b0000");
controller.getYLegend().setSize(12);
controller.getXLegend().setText("Months");
controller.getXLegend().setColor("#8b0000");
controller.getXLegend().setSize(12);
controller.getColor().getBgColor().setColor("#FFFFFF");
controller.getColor().getXAxisColor().setColor("#e3e3e3");
controller.getColor().getYAxisColor().setColor("#e3e3e3");
controller.getColor().getXGridColor().setColor("#e3e3e3");
controller.getColor().getYGridColor().setColor("#e3e3e3");

DefaultOFCGraphDataModel model = new DefaultOFCGraphDataModel();
model.setData(Arrays.asList(data01));
model.setFormat(new DecimalFormat("###0.000"));
// model.setSeriesType(new OFCLineAreaSeriesType(10,"#8b0000", "Test 2"
// ));
model.setSeriesType(new PieChart(60, "#505050",
"{font-size: 12px; color: #8b0000}"));
controller.add(model);

// model = new DefaultOFCGraphDataModel();
// model.setData(Arrays.asList(data02));
// model.setFormat(new DecimalFormat("###0.000"));
// model.setSeriesType(new OFCLineDotSeriesType(3, "#8b0000", "Test 2",
// 10, 6));
// controller.add(model);

// model = new DefaultOFCGraphDataModel();
// model.setData(Arrays.asList(data03));
// model.setFormat(new DecimalFormat("###0.000"));
// model.setSeriesType(new OFCLineSeriesType(2, "#8b0000", "Example",
// 4));
// controller.add(model);
//
// model = new DefaultOFCGraphDataModel();
// model.setData(Arrays.asList(data04));
// model.setFormat(new DecimalFormat("###0.000"));
// model.setSeriesType(new OFCFilledBarSeriesType(50, "#8b0000",
// "#8b0000", "Filled Bar"));
// controller.add(model);

value = controller.render();
return SUCCESS;
}

private static Double[] data01 = new Double[] { new Double(1.4),
new Double(6.3), new Double(7.2), new Double(4.1), new Double(5.4),
new Double(3.8), new Double(1.5), new Double(4.4), new Double(8.9),
new Double(8.6), new Double(8.7), new Double(2.4), new Double(3.5), };

private static Double[] data02 = new Double[] { new Double(3.5),
new Double(1.4), new Double(2.3), new Double(8.4), new Double(9.6),
new Double(4.4), new Double(3.8), new Double(1.5), new Double(2.8),
new Double(8.3), new Double(5.4), new Double(8.7), new Double(1.4) };

private static Double[] data03 = new Double[] { new Double(13.5),
new Double(11.4), new Double(12.3), new Double(18.4),
new Double(19.6), new Double(14.4), new Double(13.8),
new Double(11.5), new Double(12.8), new Double(18.3),
new Double(15.4), new Double(18.7), new Double(11.4) };

private static Double[] data04 = new Double[] { new Double(13.5),
new Double(11.4), new Double(12.3), new Double(18.4),
new Double(19.6), new Double(14.4), new Double(13.8),
new Double(11.5), new Double(12.8), new Double(18.3),
new Double(15.4), new Double(18.7), new Double(11.4) };

private static String[] labels = new String[] { "Jan", "Feb", "Mar", "Apr",
"May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "Jan" };

public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}

}

注意蓝色字体:connext-graphs-0.6.jar 这个版本已经实现很多的图形显示

OFCBar3DSeriesType

OFCBarSeriesType

OFCBarSketchSeriesType

OFCFilledBarSeriesType

。。。。。。。。

我就是多说了,自己慢慢试下就知道了。

不过connext-graphs-0.6.jar 还没有实现pie(饼状图),但我要用,所以我自己临时写了个实现Pie的PieChart:

public class PieChart implements OFCSeriesType {

//SET CHART STYPE PIE
public static final String SERIES_TYPE_PIE = "pie";
private int index;
private String type;
private int alpha;
private String line_colour;
//SET DISPLAY STYLE
private String style;

@Override
public int getIndex() {
return index;
}

@Override
public String getType() {
return type = SERIES_TYPE_PIE;
}

@Override
public void setIndex(int index) {
this.index = index;
}

public PieChart(int alpha, String line_colour, String style) {
this.alpha = alpha;
this.line_colour = line_colour;
this.style = style;
}

@Override
public String render() {
String value = "&" + getType();
value = value + "=" + getAlpha() + "," + getLine_colour() + ","
+ getStyle();
value = value + "&\r\n";
return value;
}

public int getAlpha() {
return alpha;
}

public void setAlpha(int alpha) {
this.alpha = alpha;
}

public String getLine_colour() {
return line_colour;
}

public void setLine_colour(String line_colour) {
this.line_colour = line_colour;
}

public String getStyle() {
return style;
}

public void setStyle(String style) {
this.style = style;
}

}

还有就是 PieLabels

public class PieLabels extends OFCGraphLabels {

//set display type pie
public static final String myPieGraphLabels = "pie_labels";
//set display colours
public static final String myPieColours = "colours";
//TODO SET LIST
private List<String> colours;

private List labels = new ArrayList();

public void setLabels(List labels) {
this.labels = labels;
}

public void clear() {
this.labels.clear();
}

public void add(String label) {
this.labels.add(label);
}

/**
* @see za.co.connext.web.components.OFCRenderer#render()
*/
public String render() {

String value = "&" + myPieGraphLabels + "=";
for (int i = 0; i < this.labels.size(); i++) {
if (i > 0)
value = value + ",";

Object x = this.labels.get(i);
if (x != null) {
value = value + x.toString();
}
}
value = value + "&\r\n";
// set colours
value = value + "&" + myPieColours + "=";
for (String str : getColours()) {
value = value+str + ",";
}
value = value + "&\r\n";
return value;
}

public List<String> getColours() {
return colours;
}

public void setColours(List<String> colours) {
this.colours = colours;
}
}

写两个jsp页面:in.jsp result.jsp

in.jsp

<%@ taglib prefix="m" uri="/connext"%>
<m:graph id="graph" width="800" height="300" align="middle"
bgcolor="#FFFFFF" url="/Graph_example.action" />

result.jsp

<%@ taglib uri="/struts-tags" prefix="s" %>
<%
response.addHeader("Pragma", "No-cache");
response.addHeader("Cache-Control", "no-cache");
response.addDateHeader("Expires", 0);
%>
<s:property value="value" escape="false" />

在struts.xml中配置下:

<action name="Graph_example" class="你的action">
<result>/result.jsp</result>
</action>


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/bluelzx/archive/2008/01/30/2073160.aspx

你可能感兴趣的:(jsp,freemarker,SVN,struts,Flash)