Echarts饼图展示动态数据

Echarts饼图展示动态数据

注:本例是在SSM框架基础上实现的,通过其他框架或servlet也同样可以实现;(不要纠结于此)

echarts.jsp文件

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions"  prefix="fn"%>


	
		
		饼图测试
        
        
        
        
		
		
	
	
		

User.java文件

package com.java.bug.beans;
import org.apache.ibatis.type.Alias;

/**
 * 描述:用户实体类
 */
@Alias("user")
public class User {

    private Long id;// 编号
    
    private String name;// 姓名
    
    private Long age;// 年龄
    

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Long getAge() {
        return age;
    }

    public void setAge(Long age) {
        this.age = age;
    }

}

UserController.java文件

package com.java.bug.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.java.bug.beans.User;
import com.java.bug.service.IUserService;

import net.sf.json.JSONArray;

@RestController
@RequestMapping("/user")
public class UserController extends BaseController{
	
	@Autowired
	IUserService userService;
	
	@RequestMapping(value="/getPie",method={RequestMethod.POST,RequestMethod.GET})
	public String getPie(HttpServletResponse response){
		Map map = new HashMap();
		List userserList = userService.selectUserByCondition(map);
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = null;
		try {
			out = response.getWriter();
		} catch (IOException e) {
			e.printStackTrace();
		}
		out.write(JSONArray.fromObject(userserList).toString());// 饼图
		out.flush();
		return null;
	}

}

UserService.java文件

package com.java.bug.service;

import java.util.List;
import java.util.Map;

import com.java.bug.beans.User;

/**
 * 描述:UserService
 */
public interface IUserService {

	/**
	 * 条件查询 ||通过外键查询
	 */
	public List selectUserByCondition(Map map);
}

UserServiceImpl.java文件

package com.java.bug.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.java.bug.beans.User;
import com.java.bug.dao.UserDao;
import com.java.bug.service.IUserService;

/**
 * 描述:UserServiceImpl
 */
@Service("userService")
public class UserServiceImpl implements IUserService {

	@Autowired
	private  UserDao userDao;

	@Override
	public List selectUserByCondition(Map map) {
		return userDao.selectUserByCondition(map);
	}
}

UserDao.java文件

package com.java.bug.dao;


import java.util.List;
import java.util.Map;

import com.java.bug.beans.User;

/**
 * 描述:UserDao
 */
public interface UserDao extends BaseDao {

	/**
	 * 条件查询 
	 */
	public List selectUserByCondition(Map map);
}

User.xml文件




	
	

User.sql文件(脚本)

/*
Navicat MySQL Data Transfer

Source Server         : localhost
Source Server Version : 50623
Source Host           : localhost:3306
Source Database       : bug

Target Server Type    : MYSQL
Target Server Version : 50623
File Encoding         : 65001

Date: 2018-10-19 16:33:34
*/

SET FOREIGN_KEY_CHECKS=0;

-- ----------------------------
-- Table structure for `User`
-- ----------------------------
DROP TABLE IF EXISTS `User`;
CREATE TABLE `User` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) DEFAULT NULL,
  `age` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of User
-- ----------------------------
INSERT INTO `User` VALUES ('1', '高圆圆', '20');
INSERT INTO `User` VALUES ('2', '赵丽颖', '22');
INSERT INTO `User` VALUES ('3', '江莱', '24');

效果图:

Echarts饼图展示动态数据_第1张图片

你可能感兴趣的:(java的,HTML/JavaScript,echarts饼图展示动态数据)