Extjs 4 生成饼状图的例子

前台:

//远程抄表设备下落图表数据
var Store1 = new Ext.data.Store({
<span style="white-space:pre">		</span>proxy:{
<span style="white-space:pre">			</span>type:'ajax',
<span style="white-space:pre">			</span>url:'/newmaterial/servlet/GetCountChartGoDatas',
<span style="white-space:pre">			</span>reader:{
<span style="white-space:pre">				</span>type:'array'
<span style="white-space:pre">			</span>}<span style="white-space:pre">	</span>
<span style="white-space:pre">		</span>},
<span style="white-space:pre">		</span>fields:[
<span style="white-space:pre">			</span>"System",
<span style="white-space:pre">			</span>{name:"Share",type:"float"}
<span style="white-space:pre">		</span>]
});
Store1.load();

var mychart1 = new Ext.chart.Chart({
<span style="white-space:pre">	</span>store:Store1,
<span style="white-space:pre">	</span>title:'所有物料去向概览',
<span style="white-space:pre">	</span>width:500,
<span style="white-space:pre">	</span>height:500,
<span style="white-space:pre">	</span>insetPadding:50,
<span style="white-space:pre">	</span>legend:{position:"right"},
<span style="white-space:pre">	</span>series:[{
<span style="white-space:pre">		</span>type:'pie',
<span style="white-space:pre">		</span>field:'Share',
<span style="white-space:pre">		</span>showInLegend:true,
<span style="white-space:pre">		</span>highlight:{
<span style="white-space:pre">			</span>segment:{margin:20}
<span style="white-space:pre">		</span>},
<span style="white-space:pre">		</span>label:{
<span style="white-space:pre">			</span>field:'System',
<span style="white-space:pre">			</span>display:'rotate',
<span style="white-space:pre">			</span>contrast:true
<span style="white-space:pre">		</span>},
<span style="white-space:pre">		</span>tips:{
<span style="white-space:pre">			</span>trackMouse:true,
<span style="white-space:pre">			</span>renderer:function(rec,item){
<span style="white-space:pre">				</span>this.update(rec.get("System")+':'+rec.get("Share")+'%');
<span style="white-space:pre">			</span>}
<span style="white-space:pre">		</span>}
<span style="white-space:pre">	</span>
<span style="white-space:pre">	</span>}]
});

后台:

public class GetCountChartGoDatas extends HttpServlet {

	/**
	 * @Fields serialVersionUID :
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 *
	 * @param request
	 *            the request send by the client to the server
	 * @param response
	 *            the response send by the server to the client
	 * @throws ServletException
	 *             if an error occurred
	 * @throws IOException
	 *             if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html");
		StringBuffer sb = new StringBuffer();
		NowmaterialDAO nmd = new NowmaterialDAO();
		MaterialDAO md = new MaterialDAO();
		List getlist = nmd.getSession().createCriteria(Nowmaterial.class)
				.setProjection(
						Projections.projectionList()
								.add(Projections.rowCount()).add(
										Projections.groupProperty("material.msCode")))
				.list();
		int total = 0;
		for (int i = 0; i < getlist.size(); i++) {
			Object[] row = (Object[]) getlist.get(i);
			total = total + Integer.parseInt(row[0].toString());
		}
		response.setCharacterEncoding("utf-8");
		sb.append("[");

		for (int i = 0; i < getlist.size(); i++) {
			Object[] row = (Object[]) getlist.get(i);
			List<Material> getonelist = md.findByProperty("msCode", row[1]);
			sb.append("['" + getonelist.get(0).getMsName() + "',"
					+ Float.parseFloat(row[0].toString()) + "],");
		}
		sb.append("]");
		int qu = sb.lastIndexOf(",");
		sb.deleteCharAt(qu);
		response.getWriter().print(sb.toString());
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to
	 * post.
	 *
	 * @param request
	 *            the request send by the client to the server
	 * @param response
	 *            the response send by the server to the client
	 * @throws ServletException
	 *             if an error occurred
	 * @throws IOException
	 *             if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);

	}

}

版权声明:本文博主原创文章。博客,未经同意不得转载。

时间: 2024-10-25 02:37:21

Extjs 4 生成饼状图的例子的相关文章

Extjs 4 生成饼状图实例

前台: //远程读取设备去向图表数据 var Store1 = new Ext.data.Store({ <span style="white-space:pre"> </span>proxy:{ <span style="white-space:pre"> </span>type:'ajax', <span style="white-space:pre"> </span>u

JFreeChart框架中生成饼状图上怎样显示数据 [问题点数:40分,结帖人GreenLawn]

我用JFreeChart框架生成饼状图,但想把数据信息在饼图上显示,是在饼图内部(即圆内)显示!怎样实现啊?? 去掉lablepieplot.setLabelGenerator(null);去掉线pieplot.setLabelLinksVisible(false); 饼图标签显示百分比方法PiePlot pp = (PiePlot)chart.getPlot();pp.setLabelGenerator(new StandardPieSectionLabelGenerator("{2}&quo

php 生成饼状图,折线图,条形图 通用类 2

生成饼状图,折线图,条形图通用的php类,这里使用的是国外的 HighCharts,前台页面别忘了调用HighCahrt  js HighCharts中文网站  http://www.hcharts.cn/index.php <?php /** * Created by PhpStorm. * User: WANG * Date: 2015/7/26 * Time: 11:19 */ namespace Org\Wechat; class HighCharts { /** * 获得js生成图表的

JfreeChart在EXCEL中生成饼状图/柱状图/折线图

Maven <dependency> <groupId>jfree</groupId> <artifactId>jfreechart</artifactId> <version>1.0.13</version> </dependency> Java import org.apache.poi.ss.usermodel.Drawing; import org.apache.poi.ss.usermodel.She

Echarts生成饼状图、条形图以及线形图 JS封装

1.在我们开发程序中,经常会用到生成一些报表,比方说饼状图,条形图,折线图等.不多说了,直接上封装好的代码,如下Echarts.js所示 以下代码是封装在Echarts.js文件中 /** * Created by Administrator on 2015/8/7. */ var charec; // 路径配置 require.config({ paths: { echarts: 'http://echarts.baidu.com/build/dist' } }); // 按需加载所需图表 r

PHP实现动态生成饼状图、柱状图和折线图(转载)

PHP在图像操作方面的表现非常出色,我们只需借助可以免费得到的GD库便可以轻松实现图.表勾画.下面将分别介绍PHP实现的饼状图.折线图和柱状图以 及他们的使用方法,这几段代码的特点就是不需要再把它们复制到你的代码之中,只需要把计算得到的数据作为参数传入,即可得到相应的图形效果 代码中所有使用的函数的说明,请参见php开发文档 饼状图 设计思路 饼状图表对于查看一个值占总值的百分比是一个好的方法.我们就用PHP来实现一个饼形图表. 它的设计思想是: 1 接受参数,得到所有数值的和,得到每一个值占数

PHP实现动态生成饼状图 (转载)

<?php //变量定义,画椭圆弧时的角度大小 define("ANGLELENGTH", 10); /** * 绘制图片 * @param $title 3D图的标题 * @param $dataArr 显示的数据数组 * @param $labelArr 对应数据的标签分类数组 * @param $colorArr 对应绘图颜色的数组 * @param $a 画布的基准宽度 * @param $b 画布的基准高度 * @param $v 3D柱的高度 * @param $fo

chart.js生成饼状图

第一步:引入chart.js. <script src='https://cdn.bootcss.com/Chart.js/2.7.3/Chart.js'></script> 第二步:在html中写入canvas元素. <canvas id="myChart" width="500px" height="150px"></canvas> 第三步:绘图. <script src='https:/

PHP画矩形,椭圆,圆,画椭圆弧 ,饼状图

1:画矩形: imagerectangle ( resource $image , int $x1 , int $y1 , int $x2 , int $y2 , int $col ) imagerectangle() 用 col 颜色在 image 图像中画一个矩形,其左上角坐标为 x1, y1,右下角坐标为 x2, y2.图像的左上角坐标为 0, 0. 2:画椭圆: imageellipse ( resource $image , int $cx , int $cy , int $width