您好,登錄后才能下訂單哦!
這篇文章給大家介紹Springboot中怎么利用echarts實(shí)現(xiàn)可視化,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對(duì)大家能有所幫助。
1.搭建springboot項(xiàng)目,maven搭建,這是項(xiàng)目整體架構(gòu)
2.后臺(tái)代碼:
@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>
關(guān)于Springboot中怎么利用echarts實(shí)現(xiàn)可視化就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。