这篇文章给大家介绍Springboot中怎么利用echarts实现可视化,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。
1.搭建springboot项目,maven搭建,这是项目整体架构
2.后台代码:
@RestController@RequestMapping("/wanglk_bds")public class VisualController { @Autowired private VisualInterface visualInterface; /** * 每一天的访问用户量 * @return */ @RequestMapping(value="/bar-simple",method=RequestMethod.GET,produces="application/json") @ResponseBody public List<DayTotal> getDateTotal(){ List<DayTotal> all = visualInterface.getAll(); return all; }}
@Servicepublic class VisualInterfaceImpl implements VisualInterface { @Autowired VisualMapper visualMapper; @Override public List<DayTotal> getAll() { List<DayTotal> totals = visualMapper.selectAllFromTable(); return totals; }}
@Mapperpublic interface VisualMapper { List<DayTotal> selectAllFromTable();}
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mapper namespace="com.wanglk_bds.visual.mapper.VisualMapper"> <resultMap id="BaseResultMap" type="com.wanglk_bds.visual.bean.DayTotal"> <result column="date" jdbcType="VARCHAR" property="date" /> <result column="total" jdbcType="VARCHAR" property="total" /> </resultMap> <sql id="Base_Column_List"> date,total </sql> <select id="selectAllFromTable" resultMap="BaseResultMap"> select <include refid="Base_Column_List" /> from keyword </select></mapper>
3.前端代码:
<!DOCTYPE html><html > <head> <meta charset="utf-8"> </head> <body > <script type="text/javascript" src="echarts.min.js"></script> <script type="text/javascript" src="jquery-1.11.3.min.js"></script> <p id="mainChart" ></p> <script type="text/javascript"> var dom = document.getElementById("mainChart"); var myChart = echarts.init(dom); myChart.clear(); $.ajax({ method:'get', url:'http://localhost:8888/wanglk_bds/bar-simple', dataType:'json', success:function(data){ var option = { xAxis: { name: '日期', type: 'category', data: [data[0].date, data[1].date, data[2].date, data[3].date, data[4].date, data[5].date, data[6].date, data[7].date, data[8].date, data[9].date, data[10].date, data[11].date] }, yAxis: { name:'访问量' }, series: [{ data: [data[0].total, data[1].total, data[2].total, data[3].total, data[4].total, data[5].total, data[6].total, data[7].total, data[8].total, data[9].total, data[10].total, data[11].total], type: 'bar' }] }; myChart.setOption(option, true); } }); </script> </body></html>
关于Springboot中怎么利用echarts实现可视化就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。