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>

发表于 @ 2008年01月30日 14:57:00 | 评论( 0 ) | 编辑| 举报| 收藏

旧一篇:get struts2 nightly build | 新一篇:STRUTS2 TAG给bluelzx的留言只有注册用户才能发表评论!登录注册姓   名:
校验码:
 Csdn Blog version 3.1a
Copyright © bluelzx  

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

As an AI language model, I am not able to create visuals or write code. However, I can provide you with the general steps to create a 5 layers pie chart with AAChartKit: 1. Import the AAChartKit library into your Xcode project. 2. Create an instance of AAChartView and set its frame. 3. Set the chart type to "pie". 4. Create an array of data for each layer of the pie chart. 5. Create an array of colors for each layer of the pie chart. 6. Set the series property of the AAChartView instance to an array of dictionaries, each representing a layer of the pie chart. Each dictionary should have a "name" key-value pair and a "data" key-value pair, where the "data" value is the data array for that layer. 7. Set the colors property of the AAChartView instance to the array of colors. 8. Add the AAChartView instance to your view hierarchy. Here is an example of what the code might look like: ```swift import AAChartKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() let chartView = AAChartView(frame: CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height)) chartView.chartType = .pie let data1 = [25, 50, 100, 75, 50] let data2 = [50, 100, 75, 50, 25] let data3 = [100, 75, 50, 25, 50] let data4 = [75, 50, 25, 50, 100] let data5 = [50, 25, 50, 100, 75] let colors = ["#FFDAB9", "#FFE4C4", "#FFEBCD", "#FFF8DC", "#FAFAD2"] let series = [ ["name": "Layer 1", "data": data1], ["name": "Layer 2", "data": data2], ["name": "Layer 3", "data": data3], ["name": "Layer 4", "data": data4], ["name": "Layer 5", "data": data5] ] let chartModel = AAChartModel() .chartType(.pie) .series(series) .colorsTheme(colors) chartView.aa_drawChartWithChartModel(chartModel) self.view.addSubview(chartView) } } ``` Note that this is just an example and you may need to adjust the code to fit your specific needs.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值