分享
 
 
 

做了一个生成JFreeChart的自定义标签SONIC Taglib。不过只能生成姘图和柱图

王朝java/jsp·作者佚名  2006-01-29
窄屏简体版  字體: |||超大  

下载地址:http://www.javasp.net/jinxin/jinxin.rar (Sonic1.0)

本来可以用cwolf的。但是cwolf不能做统计。返照他的功能自己做了一个。觉得还不错。开发的时候省略了很多JFreeChart的东西。直接做一个连数据的CLASS就可以了。下面是开发指南,希望对要用JFREECHART的人有帮助。

优点:

简化了生成图形的繁琐代码,用TagLib封装了。只要数据对象就可以了

缺点:

只能生成饼图 和 柱图 其他图还没有做

Sonic Chart Tutorial

SETUP for installing the tag library

(First time user)

Tutorial: Step1

How to Install (Making sure you have the Jar File)

To use the tag library, you must first include the jar file into your project.

Put the following JAR files of the /lib directory into your web applications /WEB-INF/lib directory:

l Sonic. jar

l jfreechart-0.9.20.jar

l jcommon-0.9.5.jar

l Commons-logging. jar

Install the sonic Servlet in your Web App

You must add the following code to the web.xml file t o let yours project know the location of the TLDS

<servlet>

<servlet>

<servlet-name>DisplayChart</servlet-name>

<servlet-class>rg.jfree.chart.servlet.DisplayChart</servlet-class>

</servlet>

Additionally you should provide a servlet-mapping to tell the container which URL maps to your sonic rendering servlet.

<servlet-mapping>

<servlet-mapping>

<servlet-name>DisplayChart</servlet-name>

<url-pattern>servlet/DisplayChart</url-pattern>

</servlet-mapping>

Additionally you should proide a taglib to tell container which URL to find sonic.tld

<taglib>

<taglib>

<taglib-uri>/WEB-INF/sonic.tld</taglib-uri>

<taglib-location>/WEB-INF/sonic.tld</taglib-location>

</taglib>

二.Tutorial: Step 2

Provide a DatasetProducer

1.How to Create a PeChart DatasetProducer

l Createa a java file such ByUsingPeople_PieDB.java

Note:

1. In ByUsingPeople_PieDB.java file you must implements ProductDataSetInterface, Serializable

Below is ByUsingPeople_PieDB.java detail

import org.jfree.data.DefaultPieDataset;

import java.util.ArrayList;

import net.javasp.www.chartfactorymethod.creator.ChartCreatorInterface.ProductDataSetInterface;import java.io.Serializable;

public class IndustryGroupRequire implements ProductDataSetInterface, Serializable{

public ArrayList produceDataset() throws Exception {

// Create a DefaultPieDataset object

DefaultPieDataset ds = new DefaultPieDataset();

String total = null;

String percent = null;

ArrayList list = new ArrayList();

// The data which need set into DefaultPieDataset object

ds.setValue("第一产业比重", 36);

ds.setValue("第二产业比重", 24);

ds.setValue("第三产业比重", 20);

// Below chart show total info

String[] totalname = {"所占比重:", ""};

list.add(ds);

list.add("80"+"%");

list.add("");

list.add(totalname); //3

list.add("other"); //

return list;

}

}

Tutorial: Step 3

Define the chart in your JSP

1. Create a jsp file such as piechart.jsp

Note:

1. The taglib sonic attribute must same to <jsp useBean id> attribute Such as <sonic:plotchart id=”pieData” …> and <jsp:useBean id=”pieData” …>

2. type="piechart" type attribute must be “piechart”

Below is piechart.jsp detail

piechart.jsp

<%@ page contentType="text/html; charset=GB2312" %>

<%@taglib uri='/WEB-INF/sonic.tld' prefix='sonic' %>

<jsp:useBean id="pieData" class=" net.javasp.www.piechartdataset.ByUsingPeople_PieDB "/>

<html>

<head>

<title>

按行业分组的需求人数

</title>

</head>

<body bgcolor="#ffffff">

<div align="center">

<sonic:plotchart id="pieData" type="piechart" name="按行业分组的需求人数" hight="700" width="700" />

</div>

</body>

</html>

2.How to Create a Column Chart DatasetProducer

Note:

l Createa a java file such SupplyTotalCount.java

In ByUsingPeople_PieDB.java file you must implements ProductDataSetInterface, Serializable

import net.javasp.www.chartfactorymethod.creator.ChartCreatorInterface.ProductDataSetInterface; import java.io.Serializable;

import java.util.ArrayList;

import org.jfree.data.CategoryDataset;

import org.jfree.data.DatasetUtilities;

/**

* <p>Title: Colum3DproduceDataset</p>

* <p>Description: </p>

* <p>Copyright: Copyright (c) 2004</p>

* <p>Company: www.javasp.net</p>

* @author Jstar

* @version 1.0

*/

public class SupplyTotalCount implements ProductDataSetInterface, Serializable {

public SupplyTotalCount() {

}

public ArrayList produceDataset() throws Exception {

int total = 0;

int percent = 0;

ArrayList list = new ArrayList();

//---------------------------------需求人数-----求职人数

double[][] date = new double[][] {{322, 261}, {128, 240}};

String[] rowKeys = {"上期结转", "本期新增"};

String[] columnKeys = {"需求人数", "求职人数"};

String[] totalname = {"需求人数", "求职人数"};

CategoryDataset ds = DatasetUtilities.createCategoryDataset(rowKeys,columnKeys, date);

//total

for (int i = 0; i < 1; i++) {

for (int j = 0; j < date.length; j++) {

total += date[j][i];

}

}

//percent

for (int a = 1; a < 2; a++) {

for (int b = 0; b < date.length ; b++) {

percent += date[b][a];

}

}

list.add(ds);//0

list.add(Integer.toString(total));//1

list.add(Integer.toString(percent));//2

list.add(totalname);//3

list.add("other");//4

return list;

}

}

Define the chart in your JSP

2. Create a jsp file such as columnchart.jsp

Note:

3. The taglib sonic attribute must same to <jsp useBean id> attribute Such as <sonic:plotchart id=” columndata” …> and <jsp:useBean id=” columndata” …>

4. type=" columndata " type attribute must be “columndata”

Below is piechart.jsp detail

piechart.jsp

<%@ page contentType="text/html; charset=GB2312" %>

<%@taglib uri='/WEB-INF/sonic.tld' prefix='sonic' %>

<jsp:useBean id="columndata " class=" net.javasp.www.columndataset.SupplyTotalCount "/>

<html>

<head>

<title>

供求总体人数

</title>

</head>

<body bgcolor="#ffffff">

<div align="center">

<sonic:plotchart id=" columndata " type=" columchart " name="供求总体人数" width="500" hight="350 " />

</div>

</body>

</html>

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有