Python 爬取 热词并进行分类数据分析-[热词关系图+报告生成]
日期:2020.02.05
博客期:144
星期三
【本博客的代码如若要使用,请在下方评论区留言,之后再用(就是跟我说一声)】
所有相关跳转:
a.【简单准备】
b.【云图制作+数据导入】
c.【拓扑数据】
d.【数据修复】
e.【解释修复+热词引用】
f.【JSP演示+页面跳转】
g.【热词分类+目录生成】
h.【热词关系图+报告生成】(本期博客)
i . 【App制作】
j . 【安全性改造】
本来是说今天、昨天要写一篇完整实现的,然后今天这一篇就去写演示类的博客的!但是又怕自己查起来不方便,还是分开写吧!
按照昨天的进度我们就只剩下 热词关系图 和 报告生成 两部分需求了,今天晚上努努力吧!
1、使用 ECharts 接口实现关系图。
本来想用之前那个模板来实现热词关系图的,但是发现数据量大了以后,完全 js 承受不住,不过,难得也封装了代码,你们可以简单看一下:
com.runtask 包:
1 package com.runtask; 2 3 import org.json.JSONObject; 4 5 public class MetBuilder { 6 /*获取新节点*/ 7 public static JSONObject getPointData(String name,String des,int symbolSize,String color){ 8 LockedModel.dataSize += 1; 9 JSONObject jsonObject = new JSONObject(); 10 jsonObject.put("name",name); 11 jsonObject.put("des",des); 12 jsonObject.put("symbolSize",symbolSize); 13 JSONObject job1 = new JSONObject(); 14 JSONObject job2 = new JSONObject(); 15 job1.put("color",color); 16 job2.put("normal",job1); 17 jsonObject.put("itemStyle",job2); 18 return jsonObject; 19 } 20 public static JSONObject getPointData(String name,String des,int symbolSize){ 21 LockedModel.dataSize += 1; 22 JSONObject jsonObject = new JSONObject(); 23 jsonObject.put("name",name); 24 jsonObject.put("des",des); 25 jsonObject.put("symbolSize",symbolSize); 26 return jsonObject; 27 } 28 /*获取新线路*/ 29 public static JSONObject getLineData(String source,String target,String name,String des){ 30 LockedModel.linkSize += 1; 31 JSONObject jsonObject = new JSONObject(); 32 jsonObject.put("name",name); 33 jsonObject.put("des",des); 34 jsonObject.put("target",target); 35 jsonObject.put("source",source); 36 return jsonObject; 37 } 38 public static JSONObject getLineData(String source,String target){ 39 LockedModel.linkSize += 1; 40 JSONObject jsonObject = new JSONObject(); 41 jsonObject.put("name",""); 42 jsonObject.put("des",""); 43 jsonObject.put("target",target); 44 jsonObject.put("source",source); 45 return jsonObject; 46 } 47 }
1 package com.runtask; 2 3 import java.sql.SQLException; 4 5 import org.json.JSONArray; 6 7 import com.dblink.basic.utils.SqlUtils; 8 import com.dblink.basic.utils.sqlKind.MySql_s; 9 import com.dblink.basic.utils.user.UserInfo; 10 import com.dblink.bean.BeanGroup; 11 import com.dblink.bean.JavaBean; 12 import com.dblink.bean.ReadableTable; 13 import com.dblink.sql.DBLink; 14 15 public class LockedModel { 16 17 public JSONArray data; 18 public JSONArray link; 19 public static int dataSize = 0; 20 public static int linkSize = 0; 21 22 //构造方法 23 public LockedModel() { 24 this.rebuild(); 25 } 26 public void rebuild(){ 27 this.data = new JSONArray(); 28 this.link = new JSONArray(); 29 LockedModel.dataSize = 0; 30 LockedModel.linkSize = 0; 31 this.buildBasicData(); 32 this.buildBasicLink(); 33 this.build(); 34 } 35 private void buildBasicData(){ 36 this.data.put(MetBuilder.getPointData("热词","所有热词",125,"green")); 37 38 this.data.put(MetBuilder.getPointData("互联网类","分类",100,"red")); 39 this.data.put(MetBuilder.getPointData("IT业界类","分类",100,"red")); 40 this.data.put(MetBuilder.getPointData("软件开发类","分类",100,"red")); 41 this.data.put(MetBuilder.getPointData("开源类","分类",100,"red")); 42 this.data.put(MetBuilder.getPointData("电脑硬件类","分类",100,"red")); 43 this.data.put(MetBuilder.getPointData("游戏类","分类",100,"red")); 44 this.data.put(MetBuilder.getPointData("创业类","分类",100,"red")); 45 this.data.put(MetBuilder.getPointData("手机相关类","分类",100,"red")); 46 this.data.put(MetBuilder.getPointData("科学类","分类",100,"red")); 47 this.data.put(MetBuilder.getPointData("其他类","分类",100,"red")); 48 } 49 private void buildBasicLink(){ 50 this.link.put(MetBuilder.getLineData("热词","互联网类")); 51 this.link.put(MetBuilder.getLineData("热词","IT业界类")); 52 this.link.put(MetBuilder.getLineData("热词","软件开发类")); 53 this.link.put(MetBuilder.getLineData("热词","开源类")); 54 this.link.put(MetBuilder.getLineData("热词","电脑硬件类")); 55 this.link.put(MetBuilder.getLineData("热词","游戏类")); 56 this.link.put(MetBuilder.getLineData("热词","创业类")); 57 this.link.put(MetBuilder.getLineData("热词","手机相关类")); 58 this.link.put(MetBuilder.getLineData("热词","科学类")); 59 this.link.put(MetBuilder.getLineData("热词","其他类")); 60 } 61 private void build(){ 62 this.makeOneTable("互联网类","互联网类"); 63 this.makeOneTable("手机相关类","手机相关类"); 64 this.makeOneTable("其他类","其他类"); 65 this.makeOneTable("电脑硬件类","电脑硬件类"); 66 this.makeOneTable("软件开发类","软件开发类"); 67 this.makeOneTable("开源类","开源类"); 68 this.makeOneTable("游戏类","游戏类"); 69 this.makeOneTable("创业类","创业类"); 70 this.makeOneTable("科学类","科学类"); 71 this.makeOneTable("IT业界类","IT业界类"); 72 } 73 private void makeOneTable(String tableName,String linkSource){ 74 DBLink dbLink = new DBLink(new SqlUtils(new MySql_s("rc"),new UserInfo("root","123456"))); 75 try { 76 ReadableTable rt = dbLink.getSelect("Select word As word , SUM(num) As num From "+tableName+" Group By word Order By num DESC Limit 0,10"); 77 BeanGroup bg = rt.beans; 78 79 int leng_bg = bg.size(); 80 81 for(int i=0;i<leng_bg;++i) 82 { 83 JavaBean jbs = bg.get(i); 84 String nam = jbs.get(0).toString(); 85 String str = "名称:"+nam+"<br>引用次数:"+jbs.get(1); 86 87 this.data.put(MetBuilder.getPointData(nam,str,50)); 88 this.link.put(MetBuilder.getLineData(linkSource,nam)); 89 } 90 } catch (SQLException e) { 91 e.printStackTrace(); 92 } 93 } 94 public static void main(String[] args) { 95 LockedModel lm = new LockedModel(); 96 System.out.println(lm.data.toString()); 97 System.out.println(); 98 System.out.println(lm.link.toString()); 99 System.out.println(); 100 System.out.println(LockedModel.dataSize); 101 System.out.println(); 102 System.out.println(LockedModel.linkSize); 103 } 104 } 105 106 LockedModel.java
对应导入 js 文件:
1 function makePageToRe() 2 { 3 var Area = ''; 4 Area += '<div class="row">'; 5 Area += ' <div class="col-md-12">'; 6 Area += ' <h2>热词关系图</h2>'; 7 Area += ' </div>'; 8 Area += '</div>'; 9 Area += '<hr />'; 10 Area += '<br>'; 11 Area += '<br>'; 12 Area += '<div id="MessageArea">'; 13 Area += " <br>"; 14 Area += " <div id='main' style='width:1150px;height:800px;'></div>"; 15 Area += " <br>"; 16 Area += '</div>'; 17 document.getElementById("page-inner").innerHTML = Area; 18 19 // 动态加载数据 20 //readAndDeal(); 21 // 静态加载数据 22 build_SameData(); 23 } 24 function readAndDeal() 25 { 26 var xmlHttp = null; 27 try{ 28 xmlHttp = new XMLHttpRequest(); 29 } catch (e1) { 30 try { 31 xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 32 } catch (e2) { 33 alert("Your browser does not support XMLHTTP!"); 34 return; 35 } 36 } 37 xmlHttp.onreadystatechange = function() { 38 if (xmlHttp.readyState == 4) { 39 if (xmlHttp.status == 200) 40 { 41 s = xmlHttp.responseText; 42 var InformationSet = eval('('+s+')'); 43 var da = InformationSet.DATA; 44 var li = InformationSet.LINK; 45 46 build_Change_Worth_Deal(da,li); 47 } 48 } 49 }; 50 var url ="../com/servlet/ServletForImage"; 51 52 xmlHttp.open("POST", url, true); 53 xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 54 xmlHttp.send(null); 55 } 56 function build_SameData() 57 { 58 var li = [{"des":"","name":"","source":"\u70ed\u8bcd","target":"\u4e92\u8054\u7f51\u7c7b"},{"des":"","name":"","source":"\u70ed\u8bcd","target":"IT\u4e1a\u754c\u7c7b"},{"des":"","name":"","source":"\u70ed\u8bcd","target":"\u8f6f\u4ef6\u5f00\u53d1\u7c7b"},{"des":"","name":"","source":"\u70ed\u8bcd","target":"\u5f00\u6e90\u7c7b"},{"des":"","name":"","source":"\u70ed\u8bcd","target":"\u7535\u8111\u786c\u4ef6\u7c7b"},{"des":"","name":"","source":"\u70ed\u8bcd","target":"\u6e38\u620f\u7c7b"},{"des":"","name":"","source":"\u70ed\u8bcd","target":"\u521b\u4e1a\u7c7b"},{"des":"","name":"","source":"\u70ed\u8bcd","target":"\u624b\u673a\u76f8\u5173\u7c7b"},{"des":"","name":"","source":"\u70ed\u8bcd","target":"\u79d1\u5b66\u7c7b"},{"des":"","name":"","source":"\u70ed\u8bcd","target":"\u5176\u4ed6\u7c7b"},{"des":"","name":"","source":"\u4e92\u8054\u7f51\u7c7b","target":"5G"},{"des":"","name":"","source":"\u4e92\u8054\u7f51\u7c7b","target":"\u6211\u4eec"},{"des":"","name":"","source":"\u4e92\u8054\u7f51\u7c7b","target":"\u6280\u672f"},{"des":"","name":"","source":"\u4e92\u8054\u7f51\u7c7b","target":"\u673a\u5668\u4eba"},{"des":"","name":"","source":"\u4e92\u8054\u7f51\u7c7b","target":"\u4e00\u4e2a"},{"des":"","name":"","source":"\u4e92\u8054\u7f51\u7c7b","target":"\u516c\u53f8"},{"des":"","name":"","source":"\u4e92\u8054\u7f51\u7c7b","target":"AI"},{"des":"","name":"","source":"\u4e92\u8054\u7f51\u7c7b","target":"\u4e2d\u56fd"},{"des":"","name":"","source":"\u4e92\u8054\u7f51\u7c7b","target":"\u6570\u636e"},{"des":"","name":"","source":"\u4e92\u8054\u7f51\u7c7b","target":"\u4eba\u5de5\u667a\u80fd"},{"des":"","name":"","source":"\u624b\u673a\u76f8\u5173\u7c7b","target":"\u624b\u673a"},{"des":"","name":"","source":"\u624b\u673a\u76f8\u5173\u7c7b","target":"\u5c0f\u7c73"},{"des":"","name":"","source":"\u624b\u673a\u76f8\u5173\u7c7b","target":"\u82f9\u679c"},{"des":"","name":"","source":"\u624b\u673a\u76f8\u5173\u7c7b","target":"\u534e\u4e3a"},{"des":"","name":"","source":"\u624b\u673a\u76f8\u5173\u7c7b","target":"iPhone"},{"des":"","name":"","source":"\u624b\u673a\u76f8\u5173\u7c7b","target":"\u5e02\u573a"},{"des":"","name":"","source":"\u624b\u673a\u76f8\u5173\u7c7b","target":"\u6211\u4eec"},{"des":"","name":"","source":"\u624b\u673a\u76f8\u5173\u7c7b","target":"5G"},{"des":"","name":"","source":"\u624b\u673a\u76f8\u5173\u7c7b","target":"\u5370\u5ea6"},{"des":"","name":"","source":"\u624b\u673a\u76f8\u5173\u7c7b","target":"\u4e09\u661f"},{"des":"","name":"","source":"\u5176\u4ed6\u7c7b","target":"\u7528\u6237"},{"des":"","name":"","source":"\u5176\u4ed6\u7c7b","target":"\u6211\u4eec"},{"des":"","name":"","source":"\u5176\u4ed6\u7c7b","target":"\u4ea7\u54c1"},{"des":"","name":"","source":"\u5176\u4ed6\u7c7b","target":"\u4e00\u4e2a"},{"des":"","name":"","source":"\u5176\u4ed6\u7c7b","target":"\u8bbe\u8ba1"},{"des":"","name":"","source":"\u5176\u4ed6\u7c7b","target":"\u516c\u53f8"},{"des":"","name":"","source":"\u5176\u4ed6\u7c7b","target":"\u53ef\u4ee5"},{"des":"","name":"","source":"\u5176\u4ed6\u7c7b","target":"\u7279\u65af\u62c9"},{"des":"","name":"","source":"\u5176\u4ed6\u7c7b","target":"\u5de5\u4f5c"},{"des":"","name":"","source":"\u5176\u4ed6\u7c7b","target":"\u4ed6\u4eec"},{"des":"","name":"","source":"\u7535\u8111\u786c\u4ef6\u7c7b","target":"\u5e73\u677f"},{"des":"","name":"","source":"\u7535\u8111\u786c\u4ef6\u7c7b","target":"\u82af\u7247"},{"des":"","name":"","source":"\u7535\u8111\u786c\u4ef6\u7c7b","target":"\u5904\u7406\u5668"},{"des":"","name":"","source":"\u7535\u8111\u786c\u4ef6\u7c7b","target":"\u7535\u8111"},{"des":"","name":"","source":"\u7535\u8111\u786c\u4ef6\u7c7b","target":"\u6211\u4eec"},{"des":"","name":"","source":"\u7535\u8111\u786c\u4ef6\u7c7b","target":"\u82f1\u7279\u5c14"},{"des":"","name":"","source":"\u7535\u8111\u786c\u4ef6\u7c7b","target":"\u786c\u76d8"},{"des":"","name":"","source":"\u7535\u8111\u786c\u4ef6\u7c7b","target":"iPad"},{"des":"","name":"","source":"\u7535\u8111\u786c\u4ef6\u7c7b","target":"AMD"},{"des":"","name":"","source":"\u7535\u8111\u786c\u4ef6\u7c7b","target":"\u534e\u4e3a"},{"des":"","name":"","source":"\u8f6f\u4ef6\u5f00\u53d1\u7c7b","target":"\u6211\u4eec"},{"des":"","name":"","source":"\u8f6f\u4ef6\u5f00\u53d1\u7c7b","target":"\u4e00\u4e2a"},{"des":"","name":"","source":"\u8f6f\u4ef6\u5f00\u53d1\u7c7b","target":"\u53ef\u4ee5"},{"des":"","name":"","source":"\u8f6f\u4ef6\u5f00\u53d1\u7c7b","target":"\u5b66\u4e60"},{"des":"","name":"","source":"\u8f6f\u4ef6\u5f00\u53d1\u7c7b","target":"\u6570\u636e"},{"des":"","name":"","source":"\u8f6f\u4ef6\u5f00\u53d1\u7c7b","target":"\u6a21\u578b"},{"des":"","name":"","source":"\u8f6f\u4ef6\u5f00\u53d1\u7c7b","target":"\u6280\u672f"},{"des":"","name":"","source":"\u8f6f\u4ef6\u5f00\u53d1\u7c7b","target":"\u95ee\u9898"},{"des":"","name":"","source":"\u8f6f\u4ef6\u5f00\u53d1\u7c7b","target":"\u4ee3\u7801"},{"des":"","name":"","source":"\u8f6f\u4ef6\u5f00\u53d1\u7c7b","target":"\u6e38\u620f"},{"des":"","name":"","source":"\u5f00\u6e90\u7c7b","target":"\u5f00\u6e90"},{"des":"","name":"","source":"\u5f00\u6e90\u7c7b","target":"\u6211\u4eec"},{"des":"","name":"","source":"\u5f00\u6e90\u7c7b","target":"\u4e00\u4e2a"},{"des":"","name":"","source":"\u5f00\u6e90\u7c7b","target":"Linux"},{"des":"","name":"","source":"\u5f00\u6e90\u7c7b","target":"\u9879\u76ee"},{"des":"","name":"","source":"\u5f00\u6e90\u7c7b","target":"\u53ef\u4ee5"},{"des":"","name":"","source":"\u5f00\u6e90\u7c7b","target":"\u8f6f\u4ef6"},{"des":"","name":"","source":"\u5f00\u6e90\u7c7b","target":"\u6570\u636e"},{"des":"","name":"","source":"\u5f00\u6e90\u7c7b","target":"\u5b66\u4e60"},{"des":"","name":"","source":"\u5f00\u6e90\u7c7b","target":"GitHub"},{"des":"","name":"","source":"\u6e38\u620f\u7c7b","target":"\u6e38\u620f"},{"des":"","name":"","source":"\u6e38\u620f\u7c7b","target":"\u73a9\u5bb6"},{"des":"","name":"","source":"\u6e38\u620f\u7c7b","target":"\u6211\u4eec"},{"des":"","name":"","source":"\u6e38\u620f\u7c7b","target":"\u7f51\u6e38"},{"des":"","name":"","source":"\u6e38\u620f\u7c7b","target":"\u4e00\u4e2a"},{"des":"","name":"","source":"\u6e38\u620f\u7c7b","target":"\u516c\u53f8"},{"des":"","name":"","source":"\u6e38\u620f\u7c7b","target":"\u7528\u6237"},{"des":"","name":"","source":"\u6e38\u620f\u7c7b","target":"\u4e2d\u56fd"},{"des":"","name":"","source":"\u6e38\u620f\u7c7b","target":"\u66b4\u96ea"},{"des":"","name":"","source":"\u6e38\u620f\u7c7b","target":"\u4ea7\u54c1"},{"des":"","name":"","source":"\u521b\u4e1a\u7c7b","target":"\u516c\u53f8"},{"des":"","name":"","source":"\u521b\u4e1a\u7c7b","target":"\u6211\u4eec"},{"des":"","name":"","source":"\u521b\u4e1a\u7c7b","target":"\u4e00\u4e2a"},{"des":"","name":"","source":"\u521b\u4e1a\u7c7b","target":"\u521b\u4e1a"},{"des":"","name":"","source":"\u521b\u4e1a\u7c7b","target":"\u6295\u8d44"},{"des":"","name":"","source":"\u521b\u4e1a\u7c7b","target":"\u4ed6\u4eec"},{"des":"","name":"","source":"\u521b\u4e1a\u7c7b","target":"\u4ea7\u54c1"},{"des":"","name":"","source":"\u521b\u4e1a\u7c7b","target":"\u4f01\u4e1a"},{"des":"","name":"","source":"\u521b\u4e1a\u7c7b","target":"\u8fd9\u4e2a"},{"des":"","name":"","source":"\u521b\u4e1a\u7c7b","target":"\u81ea\u5df1"},{"des":"","name":"","source":"\u79d1\u5b66\u7c7b","target":"\u6211\u4eec"},{"des":"","name":"","source":"\u79d1\u5b66\u7c7b","target":"\u91cf\u5b50"},{"des":"","name":"","source":"\u79d1\u5b66\u7c7b","target":"\u9ed1\u6d1e"},{"des":"","name":"","source":"\u79d1\u5b66\u7c7b","target":"\u7814\u7a76"},{"des":"","name":"","source":"\u79d1\u5b66\u7c7b","target":"\u536b\u661f"},{"des":"","name":"","source":"\u79d1\u5b66\u7c7b","target":"\u5b87\u5b99"},{"des":"","name":"","source":"\u79d1\u5b66\u7c7b","target":"\u7ec6\u80de"},{"des":"","name":"","source":"\u79d1\u5b66\u7c7b","target":"\u4e00\u4e2a"},{"des":"","name":"","source":"\u79d1\u5b66\u7c7b","target":"\u661f\u7cfb"},{"des":"","name":"","source":"\u79d1\u5b66\u7c7b","target":"\u706b\u661f"},{"des":"","name":"","source":"IT\u4e1a\u754c\u7c7b","target":"AI"},{"des":"","name":"","source":"IT\u4e1a\u754c\u7c7b","target":"\u4f01\u4e1a"},{"des":"","name":"","source":"IT\u4e1a\u754c\u7c7b","target":"\u516c\u53f8"},{"des":"","name":"","source":"IT\u4e1a\u754c\u7c7b","target":"\u6570\u636e"},{"des":"","name":"","source":"IT\u4e1a\u754c\u7c7b","target":"\u6211\u4eec"},{"des":"","name":"","source":"IT\u4e1a\u754c\u7c7b","target":"\u82af\u7247"},{"des":"","name":"","source":"IT\u4e1a\u754c\u7c7b","target":"\u6280\u672f"},{"des":"","name":"","source":"IT\u4e1a\u754c\u7c7b","target":"\u534e\u4e3a"},{"des":"","name":"","source":"IT\u4e1a\u754c\u7c7b","target":"\u8ba1\u7b97"},{"des":"","name":"","source":"IT\u4e1a\u754c\u7c7b","target":"\u817e\u8baf"}]; 59 var da = [{"des":"\u6240\u6709\u70ed\u8bcd","symbolSize":125,"name":"\u70ed\u8bcd","itemStyle":{"normal":{"color":"green"}}},{"des":"\u5206\u7c7b","symbolSize":100,"name":"\u4e92\u8054\u7f51\u7c7b","itemStyle":{"normal":{"color":"red"}}},{"des":"\u5206\u7c7b","symbolSize":100,"name":"IT\u4e1a\u754c\u7c7b","itemStyle":{"normal":{"color":"red"}}},{"des":"\u5206\u7c7b","symbolSize":100,"name":"\u8f6f\u4ef6\u5f00\u53d1\u7c7b","itemStyle":{"normal":{"color":"red"}}},{"des":"\u5206\u7c7b","symbolSize":100,"name":"\u5f00\u6e90\u7c7b","itemStyle":{"normal":{"color":"red"}}},{"des":"\u5206\u7c7b","symbolSize":100,"name":"\u7535\u8111\u786c\u4ef6\u7c7b","itemStyle":{"normal":{"color":"red"}}},{"des":"\u5206\u7c7b","symbolSize":100,"name":"\u6e38\u620f\u7c7b","itemStyle":{"normal":{"color":"red"}}},{"des":"\u5206\u7c7b","symbolSize":100,"name":"\u521b\u4e1a\u7c7b","itemStyle":{"normal":{"color":"red"}}},{"des":"\u5206\u7c7b","symbolSize":100,"name":"\u624b\u673a\u76f8\u5173\u7c7b","itemStyle":{"normal":{"color":"red"}}},{"des":"\u5206\u7c7b","symbolSize":100,"name":"\u79d1\u5b66\u7c7b","itemStyle":{"normal":{"color":"red"}}},{"des":"\u5206\u7c7b","symbolSize":100,"name":"\u5176\u4ed6\u7c7b","itemStyle":{"normal":{"color":"red"}}},{"des":"\u540d\u79f0\uff1a5G<br>\u5f15\u7528\u6b21\u6570:1269","symbolSize":50,"name":"5G"},{"des":"\u540d\u79f0\uff1a\u6211\u4eec<br>\u5f15\u7528\u6b21\u6570:1156","symbolSize":50,"name":"\u6211\u4eec"},{"des":"\u540d\u79f0\uff1a\u6280\u672f<br>\u5f15\u7528\u6b21\u6570:914","symbolSize":50,"name":"\u6280\u672f"},{"des":"\u540d\u79f0\uff1a\u673a\u5668\u4eba<br>\u5f15\u7528\u6b21\u6570:862","symbolSize":50,"name":"\u673a\u5668\u4eba"},{"des":"\u540d\u79f0\uff1a\u4e00\u4e2a<br>\u5f15\u7528\u6b21\u6570:839","symbolSize":50,"name":"\u4e00\u4e2a"},{"des":"\u540d\u79f0\uff1a\u516c\u53f8<br>\u5f15\u7528\u6b21\u6570:824","symbolSize":50,"name":"\u516c\u53f8"},{"des":"\u540d\u79f0\uff1aAI<br>\u5f15\u7528\u6b21\u6570:785","symbolSize":50,"name":"AI"},{"des":"\u540d\u79f0\uff1a\u4e2d\u56fd<br>\u5f15\u7528\u6b21\u6570:745","symbolSize":50,"name":"\u4e2d\u56fd"},{"des":"\u540d\u79f0\uff1a\u6570\u636e<br>\u5f15\u7528\u6b21\u6570:625","symbolSize":50,"name":"\u6570\u636e"},{"des":"\u540d\u79f0\uff1a\u4eba\u5de5\u667a\u80fd<br>\u5f15\u7528\u6b21\u6570:592","symbolSize":50,"name":"\u4eba\u5de5\u667a\u80fd"},{"des":"\u540d\u79f0\uff1a\u624b\u673a<br>\u5f15\u7528\u6b21\u6570:6068","symbolSize":50,"name":"\u624b\u673a"},{"des":"\u540d\u79f0\uff1a\u5c0f\u7c73<br>\u5f15\u7528\u6b21\u6570:3344","symbolSize":50,"name":"\u5c0f\u7c73"},{"des":"\u540d\u79f0\uff1a\u82f9\u679c<br>\u5f15\u7528\u6b21\u6570:3076","symbolSize":50,"name":"\u82f9\u679c"},{"des":"\u540d\u79f0\uff1a\u534e\u4e3a<br>\u5f15\u7528\u6b21\u6570:1988","symbolSize":50,"name":"\u534e\u4e3a"},{"des":"\u540d\u79f0\uff1aiPhone<br>\u5f15\u7528\u6b21\u6570:1078","symbolSize":50,"name":"iPhone"},{"des":"\u540d\u79f0\uff1a\u5e02\u573a<br>\u5f15\u7528\u6b21\u6570:1057","symbolSize":50,"name":"\u5e02\u573a"},{"des":"\u540d\u79f0\uff1a\u6211\u4eec<br>\u5f15\u7528\u6b21\u6570:993","symbolSize":50,"name":"\u6211\u4eec"},{"des":"\u540d\u79f0\uff1a5G<br>\u5f15\u7528\u6b21\u6570:978","symbolSize":50,"name":"5G"},{"des":"\u540d\u79f0\uff1a\u5370\u5ea6<br>\u5f15\u7528\u6b21\u6570:809","symbolSize":50,"name":"\u5370\u5ea6"},{"des":"\u540d\u79f0\uff1a\u4e09\u661f<br>\u5f15\u7528\u6b21\u6570:649","symbolSize":50,"name":"\u4e09\u661f"},{"des":"\u540d\u79f0\uff1a\u7528\u6237<br>\u5f15\u7528\u6b21\u6570:2776","symbolSize":50,"name":"\u7528\u6237"},{"des":"\u540d\u79f0\uff1a\u6211\u4eec<br>\u5f15\u7528\u6b21\u6570:2471","symbolSize":50,"name":"\u6211\u4eec"},{"des":"\u540d\u79f0\uff1a\u4ea7\u54c1<br>\u5f15\u7528\u6b21\u6570:2381","symbolSize":50,"name":"\u4ea7\u54c1"},{"des":"\u540d\u79f0\uff1a\u4e00\u4e2a<br>\u5f15\u7528\u6b21\u6570:2107","symbolSize":50,"name":"\u4e00\u4e2a"},{"des":"\u540d\u79f0\uff1a\u8bbe\u8ba1<br>\u5f15\u7528\u6b21\u6570:2045","symbolSize":50,"name":"\u8bbe\u8ba1"},{"des":"\u540d\u79f0\uff1a\u516c\u53f8<br>\u5f15\u7528\u6b21\u6570:1157","symbolSize":50,"name":"\u516c\u53f8"},{"des":"\u540d\u79f0\uff1a\u53ef\u4ee5<br>\u5f15\u7528\u6b21\u6570:962","symbolSize":50,"name":"\u53ef\u4ee5"},{"des":"\u540d\u79f0\uff1a\u7279\u65af\u62c9<br>\u5f15\u7528\u6b21\u6570:717","symbolSize":50,"name":"\u7279\u65af\u62c9"},{"des":"\u540d\u79f0\uff1a\u5de5\u4f5c<br>\u5f15\u7528\u6b21\u6570:670","symbolSize":50,"name":"\u5de5\u4f5c"},{"des":"\u540d\u79f0\uff1a\u4ed6\u4eec<br>\u5f15\u7528\u6b21\u6570:651","symbolSize":50,"name":"\u4ed6\u4eec"},{"des":"\u540d\u79f0\uff1a\u5e73\u677f<br>\u5f15\u7528\u6b21\u6570:469","symbolSize":50,"name":"\u5e73\u677f"},{"des":"\u540d\u79f0\uff1a\u82af\u7247<br>\u5f15\u7528\u6b21\u6570:443","symbolSize":50,"name":"\u82af\u7247"},{"des":"\u540d\u79f0\uff1a\u5904\u7406\u5668<br>\u5f15\u7528\u6b21\u6570:369","symbolSize":50,"name":"\u5904\u7406\u5668"},{"des":"\u540d\u79f0\uff1a\u7535\u8111<br>\u5f15\u7528\u6b21\u6570:362","symbolSize":50,"name":"\u7535\u8111"},{"des":"\u540d\u79f0\uff1a\u6211\u4eec<br>\u5f15\u7528\u6b21\u6570:324","symbolSize":50,"name":"\u6211\u4eec"},{"des":"\u540d\u79f0\uff1a\u82f1\u7279\u5c14<br>\u5f15\u7528\u6b21\u6570:322","symbolSize":50,"name":"\u82f1\u7279\u5c14"},{"des":"\u540d\u79f0\uff1a\u786c\u76d8<br>\u5f15\u7528\u6b21\u6570:252","symbolSize":50,"name":"\u786c\u76d8"},{"des":"\u540d\u79f0\uff1aiPad<br>\u5f15\u7528\u6b21\u6570:229","symbolSize":50,"name":"iPad"},{"des":"\u540d\u79f0\uff1aAMD<br>\u5f15\u7528\u6b21\u6570:206","symbolSize":50,"name":"AMD"},{"des":"\u540d\u79f0\uff1a\u534e\u4e3a<br>\u5f15\u7528\u6b21\u6570:201","symbolSize":50,"name":"\u534e\u4e3a"},{"des":"\u540d\u79f0\uff1a\u6211\u4eec<br>\u5f15\u7528\u6b21\u6570:4513","symbolSize":50,"name":"\u6211\u4eec"},{"des":"\u540d\u79f0\uff1a\u4e00\u4e2a<br>\u5f15\u7528\u6b21\u6570:4494","symbolSize":50,"name":"\u4e00\u4e2a"},{"des":"\u540d\u79f0\uff1a\u53ef\u4ee5<br>\u5f15\u7528\u6b21\u6570:2412","symbolSize":50,"name":"\u53ef\u4ee5"},{"des":"\u540d\u79f0\uff1a\u5b66\u4e60<br>\u5f15\u7528\u6b21\u6570:2294","symbolSize":50,"name":"\u5b66\u4e60"},{"des":"\u540d\u79f0\uff1a\u6570\u636e<br>\u5f15\u7528\u6b21\u6570:2234","symbolSize":50,"name":"\u6570\u636e"},{"des":"\u540d\u79f0\uff1a\u6a21\u578b<br>\u5f15\u7528\u6b21\u6570:1746","symbolSize":50,"name":"\u6a21\u578b"},{"des":"\u540d\u79f0\uff1a\u6280\u672f<br>\u5f15\u7528\u6b21\u6570:1579","symbolSize":50,"name":"\u6280\u672f"},{"des":"\u540d\u79f0\uff1a\u95ee\u9898<br>\u5f15\u7528\u6b21\u6570:1457","symbolSize":50,"name":"\u95ee\u9898"},{"des":"\u540d\u79f0\uff1a\u4ee3\u7801<br>\u5f15\u7528\u6b21\u6570:1427","symbolSize":50,"name":"\u4ee3\u7801"},{"des":"\u540d\u79f0\uff1a\u6e38\u620f<br>\u5f15\u7528\u6b21\u6570:1305","symbolSize":50,"name":"\u6e38\u620f"},{"des":"\u540d\u79f0\uff1a\u5f00\u6e90<br>\u5f15\u7528\u6b21\u6570:3660","symbolSize":50,"name":"\u5f00\u6e90"},{"des":"\u540d\u79f0\uff1a\u6211\u4eec<br>\u5f15\u7528\u6b21\u6570:1379","symbolSize":50,"name":"\u6211\u4eec"},{"des":"\u540d\u79f0\uff1a\u4e00\u4e2a<br>\u5f15\u7528\u6b21\u6570:1358","symbolSize":50,"name":"\u4e00\u4e2a"},{"des":"\u540d\u79f0\uff1aLinux<br>\u5f15\u7528\u6b21\u6570:1231","symbolSize":50,"name":"Linux"},{"des":"\u540d\u79f0\uff1a\u9879\u76ee<br>\u5f15\u7528\u6b21\u6570:1197","symbolSize":50,"name":"\u9879\u76ee"},{"des":"\u540d\u79f0\uff1a\u53ef\u4ee5<br>\u5f15\u7528\u6b21\u6570:745","symbolSize":50,"name":"\u53ef\u4ee5"},{"des":"\u540d\u79f0\uff1a\u8f6f\u4ef6<br>\u5f15\u7528\u6b21\u6570:660","symbolSize":50,"name":"\u8f6f\u4ef6"},{"des":"\u540d\u79f0\uff1a\u6570\u636e<br>\u5f15\u7528\u6b21\u6570:617","symbolSize":50,"name":"\u6570\u636e"},{"des":"\u540d\u79f0\uff1a\u5b66\u4e60<br>\u5f15\u7528\u6b21\u6570:588","symbolSize":50,"name":"\u5b66\u4e60"},{"des":"\u540d\u79f0\uff1aGitHub<br>\u5f15\u7528\u6b21\u6570:575","symbolSize":50,"name":"GitHub"},{"des":"\u540d\u79f0\uff1a\u6e38\u620f<br>\u5f15\u7528\u6b21\u6570:12217","symbolSize":50,"name":"\u6e38\u620f"},{"des":"\u540d\u79f0\uff1a\u73a9\u5bb6<br>\u5f15\u7528\u6b21\u6570:1577","symbolSize":50,"name":"\u73a9\u5bb6"},{"des":"\u540d\u79f0\uff1a\u6211\u4eec<br>\u5f15\u7528\u6b21\u6570:1410","symbolSize":50,"name":"\u6211\u4eec"},{"des":"\u540d\u79f0\uff1a\u7f51\u6e38<br>\u5f15\u7528\u6b21\u6570:630","symbolSize":50,"name":"\u7f51\u6e38"},{"des":"\u540d\u79f0\uff1a\u4e00\u4e2a<br>\u5f15\u7528\u6b21\u6570:584","symbolSize":50,"name":"\u4e00\u4e2a"},{"des":"\u540d\u79f0\uff1a\u516c\u53f8<br>\u5f15\u7528\u6b21\u6570:510","symbolSize":50,"name":"\u516c\u53f8"},{"des":"\u540d\u79f0\uff1a\u7528\u6237<br>\u5f15\u7528\u6b21\u6570:458","symbolSize":50,"name":"\u7528\u6237"},{"des":"\u540d\u79f0\uff1a\u4e2d\u56fd<br>\u5f15\u7528\u6b21\u6570:437","symbolSize":50,"name":"\u4e2d\u56fd"},{"des":"\u540d\u79f0\uff1a\u66b4\u96ea<br>\u5f15\u7528\u6b21\u6570:421","symbolSize":50,"name":"\u66b4\u96ea"},{"des":"\u540d\u79f0\uff1a\u4ea7\u54c1<br>\u5f15\u7528\u6b21\u6570:407","symbolSize":50,"name":"\u4ea7\u54c1"},{"des":"\u540d\u79f0\uff1a\u516c\u53f8<br>\u5f15\u7528\u6b21\u6570:16844","symbolSize":50,"name":"\u516c\u53f8"},{"des":"\u540d\u79f0\uff1a\u6211\u4eec<br>\u5f15\u7528\u6b21\u6570:9498","symbolSize":50,"name":"\u6211\u4eec"},{"des":"\u540d\u79f0\uff1a\u4e00\u4e2a<br>\u5f15\u7528\u6b21\u6570:8272","symbolSize":50,"name":"\u4e00\u4e2a"},{"des":"\u540d\u79f0\uff1a\u521b\u4e1a<br>\u5f15\u7528\u6b21\u6570:7067","symbolSize":50,"name":"\u521b\u4e1a"},{"des":"\u540d\u79f0\uff1a\u6295\u8d44<br>\u5f15\u7528\u6b21\u6570:3973","symbolSize":50,"name":"\u6295\u8d44"},{"des":"\u540d\u79f0\uff1a\u4ed6\u4eec<br>\u5f15\u7528\u6b21\u6570:3807","symbolSize":50,"name":"\u4ed6\u4eec"},{"des":"\u540d\u79f0\uff1a\u4ea7\u54c1<br>\u5f15\u7528\u6b21\u6570:2441","symbolSize":50,"name":"\u4ea7\u54c1"},{"des":"\u540d\u79f0\uff1a\u4f01\u4e1a<br>\u5f15\u7528\u6b21\u6570:2430","symbolSize":50,"name":"\u4f01\u4e1a"},{"des":"\u540d\u79f0\uff1a\u8fd9\u4e2a<br>\u5f15\u7528\u6b21\u6570:2256","symbolSize":50,"name":"\u8fd9\u4e2a"},{"des":"\u540d\u79f0\uff1a\u81ea\u5df1<br>\u5f15\u7528\u6b21\u6570:2150","symbolSize":50,"name":"\u81ea\u5df1"},{"des":"\u540d\u79f0\uff1a\u6211\u4eec<br>\u5f15\u7528\u6b21\u6570:1463","symbolSize":50,"name":"\u6211\u4eec"},{"des":"\u540d\u79f0\uff1a\u91cf\u5b50<br>\u5f15\u7528\u6b21\u6570:1205","symbolSize":50,"name":"\u91cf\u5b50"},{"des":"\u540d\u79f0\uff1a\u9ed1\u6d1e<br>\u5f15\u7528\u6b21\u6570:993","symbolSize":50,"name":"\u9ed1\u6d1e"},{"des":"\u540d\u79f0\uff1a\u7814\u7a76<br>\u5f15\u7528\u6b21\u6570:889","symbolSize":50,"name":"\u7814\u7a76"},{"des":"\u540d\u79f0\uff1a\u536b\u661f<br>\u5f15\u7528\u6b21\u6570:796","symbolSize":50,"name":"\u536b\u661f"},{"des":"\u540d\u79f0\uff1a\u5b87\u5b99<br>\u5f15\u7528\u6b21\u6570:789","symbolSize":50,"name":"\u5b87\u5b99"},{"des":"\u540d\u79f0\uff1a\u7ec6\u80de<br>\u5f15\u7528\u6b21\u6570:751","symbolSize":50,"name":"\u7ec6\u80de"},{"des":"\u540d\u79f0\uff1a\u4e00\u4e2a<br>\u5f15\u7528\u6b21\u6570:662","symbolSize":50,"name":"\u4e00\u4e2a"},{"des":"\u540d\u79f0\uff1a\u661f\u7cfb<br>\u5f15\u7528\u6b21\u6570:591","symbolSize":50,"name":"\u661f\u7cfb"},{"des":"\u540d\u79f0\uff1a\u706b\u661f<br>\u5f15\u7528\u6b21\u6570:533","symbolSize":50,"name":"\u706b\u661f"},{"des":"\u540d\u79f0\uff1aAI<br>\u5f15\u7528\u6b21\u6570:1678","symbolSize":50,"name":"AI"},{"des":"\u540d\u79f0\uff1a\u4f01\u4e1a<br>\u5f15\u7528\u6b21\u6570:1547","symbolSize":50,"name":"\u4f01\u4e1a"},{"des":"\u540d\u79f0\uff1a\u516c\u53f8<br>\u5f15\u7528\u6b21\u6570:1444","symbolSize":50,"name":"\u516c\u53f8"},{"des":"\u540d\u79f0\uff1a\u6570\u636e<br>\u5f15\u7528\u6b21\u6570:1317","symbolSize":50,"name":"\u6570\u636e"},{"des":"\u540d\u79f0\uff1a\u6211\u4eec<br>\u5f15\u7528\u6b21\u6570:1284","symbolSize":50,"name":"\u6211\u4eec"},{"des":"\u540d\u79f0\uff1a\u82af\u7247<br>\u5f15\u7528\u6b21\u6570:1148","symbolSize":50,"name":"\u82af\u7247"},{"des":"\u540d\u79f0\uff1a\u6280\u672f<br>\u5f15\u7528\u6b21\u6570:1087","symbolSize":50,"name":"\u6280\u672f"},{"des":"\u540d\u79f0\uff1a\u534e\u4e3a<br>\u5f15\u7528\u6b21\u6570:1083","symbolSize":50,"name":"\u534e\u4e3a"},{"des":"\u540d\u79f0\uff1a\u8ba1\u7b97<br>\u5f15\u7528\u6b21\u6570:1078","symbolSize":50,"name":"\u8ba1\u7b97"},{"des":"\u540d\u79f0\uff1a\u817e\u8baf<br>\u5f15\u7528\u6b21\u6570:920","symbolSize":50,"name":"\u817e\u8baf"}]; 60 build_Change_Worth_Deal(da,li); 61 } 62 function build_Change_Worth_Deal(da,li){ 63 var myChart = echarts.init(document.getElementById('main')); 64 65 var option = { 66 title: { text: '信息领域热词关系图谱' }, 67 tooltip: { 68 formatter: function (x) { 69 return x.data.des; 70 } 71 }, 72 series: [ 73 { 74 type: 'graph', 75 layout: 'force', 76 symbolSize: 80, 77 roam: true, 78 edgeSymbol: ['circle', 'arrow'], 79 edgeSymbolSize: [4, 10], 80 edgeLabel: { 81 normal: { 82 textStyle: { 83 fontSize: 20 84 } 85 } 86 }, 87 force: { 88 repulsion: 2500, 89 edgeLength: [10, 50] 90 }, 91 draggable: true, 92 itemStyle: { 93 normal: { 94 color: '#4b565b' 95 } 96 }, 97 lineStyle: { 98 normal: { 99 width: 2, 100 color: '#4b565b' 101 102 } 103 }, 104 edgeLabel: { 105 normal: { 106 show: true, 107 formatter: function (x) { 108 return x.data.name; 109 } 110 } 111 }, 112 label: { 113 normal: { 114 show: true, 115 textStyle: { 116 } 117 } 118 }, 119 data: da 120 , 121 links: li 122 } 123 ] 124 }; 125 myChart.setOption(option); 126 }
(数据量过大警告!!!)
现在要找到一个能够加载大量数据的关系图......才怪!我仔细分析了一下,根本不是这么回事儿!100项数据都能加载出来,那么几项数据怎么可能会加载不上?原因到底处在了哪里呢?其实吧,就算数据划分的问题,理想状态下,如果一个词仅仅能够被归为一个类那么,就可以生成我想的那样的 树形结构图 (如果导入出来应该是中心点为树根的星云图)。问题就是词语划分没有规定上的那么严格,这就让我们的关系图较为复杂,难以生成!那么怎么办?树形结构是怎样建立呢?建立一个 Node 结点,然后去找 它 的根结点 ,这样就绘制了一个分支,也就是说 在根节点的基础之上,我们每每建立一个新节点,就会建立一个与之对应的分支,也就是说 新建分支数 = 新建结点数。在这种情况下,我们 结点的建立 和 分支的建立是同步进行的,就像上方封装的 Java 代码一样!我们要的图的结构并不是树形结构,而是 图!所以我们要结点建立和分支建立分步进行!先结点,后分支!
建立思路:在中心结点的基础上,添加10个分类的结点,并建立相关分支(这部分是树形结构)。构建完成基础部分以后,开始以 keywords 表为中心建立结点。最后,以 10 类视图为中心建立关联。
如下图:
修改以后的 LockedModel Java 类:
1 package com.runtask; 2 3 import java.sql.SQLException; 4 5 import org.json.JSONArray; 6 import org.json.JSONObject; 7 8 import com.dblink.basic.utils.SqlUtils; 9 import com.dblink.basic.utils.sqlKind.MySql_s; 10 import com.dblink.basic.utils.user.UserInfo; 11 import com.dblink.bean.BeanGroup; 12 import com.dblink.bean.JavaBean; 13 import com.dblink.bean.ReadableTable; 14 import com.dblink.sql.DBLink; 15 16 public class LockedModel { 17 18 public JSONArray data; 19 public JSONArray link; 20 public static int dataSize = 0; 21 public static int linkSize = 0; 22 23 //构造方法 24 public LockedModel() { 25 this.rebuild(); 26 } 27 public void rebuild(){ 28 this.data = new JSONArray(); 29 this.link = new JSONArray(); 30 LockedModel.dataSize = 0; 31 LockedModel.linkSize = 0; 32 this.buildBasicData(); 33 this.buildBasicLink(); 34 this.build(); 35 } 36 private void buildBasicData(){ 37 this.data.put(MetBuilder.getPointData("热词","所有热词",125,"green")); 38 39 this.data.put(MetBuilder.getPointData("互联网类","分类",100,"red")); 40 this.data.put(MetBuilder.getPointData("IT业界类","分类",100,"red")); 41 this.data.put(MetBuilder.getPointData("软件开发类","分类",100,"red")); 42 this.data.put(MetBuilder.getPointData("开源类","分类",100,"red")); 43 this.data.put(MetBuilder.getPointData("电脑硬件类","分类",100,"red")); 44 this.data.put(MetBuilder.getPointData("游戏类","分类",100,"red")); 45 this.data.put(MetBuilder.getPointData("创业类","分类",100,"red")); 46 this.data.put(MetBuilder.getPointData("手机相关类","分类",100,"red")); 47 this.data.put(MetBuilder.getPointData("科学类","分类",100,"red")); 48 this.data.put(MetBuilder.getPointData("其他类","分类",100,"red")); 49 } 50 private void buildBasicLink(){ 51 this.link.put(MetBuilder.getLineData("热词","互联网类")); 52 this.link.put(MetBuilder.getLineData("热词","IT业界类")); 53 this.link.put(MetBuilder.getLineData("热词","软件开发类")); 54 this.link.put(MetBuilder.getLineData("热词","开源类")); 55 this.link.put(MetBuilder.getLineData("热词","电脑硬件类")); 56 this.link.put(MetBuilder.getLineData("热词","游戏类")); 57 this.link.put(MetBuilder.getLineData("热词","创业类")); 58 this.link.put(MetBuilder.getLineData("热词","手机相关类")); 59 this.link.put(MetBuilder.getLineData("热词","科学类")); 60 this.link.put(MetBuilder.getLineData("热词","其他类")); 61 } 62 private void build(){ 63 buildNode(); 64 buildLink(); 65 } 66 private void buildNode(){ 67 this.makeOneNode("互联网类"); 68 this.makeOneNode("手机相关类"); 69 this.makeOneNode("其他类"); 70 this.makeOneNode("电脑硬件类"); 71 this.makeOneNode("软件开发类"); 72 this.makeOneNode("开源类"); 73 this.makeOneNode("游戏类"); 74 this.makeOneNode("创业类"); 75 this.makeOneNode("科学类"); 76 this.makeOneNode("IT业界类"); 77 } 78 private void buildLink() { 79 this.makeOneLink("互联网类","互联网类"); 80 this.makeOneLink("手机相关类","手机相关类"); 81 this.makeOneLink("其他类","其他类"); 82 this.makeOneLink("电脑硬件类","电脑硬件类"); 83 this.makeOneLink("软件开发类","软件开发类"); 84 this.makeOneLink("开源类","开源类"); 85 this.makeOneLink("游戏类","游戏类"); 86 this.makeOneLink("创业类","创业类"); 87 this.makeOneLink("科学类","科学类"); 88 this.makeOneLink("IT业界类","IT业界类"); 89 } 90 private void makeOneNode(String tableName) { 91 DBLink dbLink = new DBLink(new SqlUtils(new MySql_s("rc"),new UserInfo("root","123456"))); 92 try { 93 ReadableTable rt = dbLink.getSelect("Select word As word , SUM(num) As num From "+tableName+" Group By word Order By num DESC Limit 0,10"); 94 BeanGroup bg = rt.beans; 95 96 int leng_bg = bg.size(); 97 98 for(int i=0;i<leng_bg;++i) 99 { 100 JavaBean jbs = bg.get(i); 101 String nam = jbs.get(0).toString(); 102 String str = "名称:"+nam+"<br>引用次数:"+jbs.get(1); 103 104 int size = this.data.length(); 105 106 boolean isAccess = true; 107 108 for(int j=0;j<size;++j) 109 { 110 JSONObject jso = this.data.getJSONObject(j); 111 if(jso.get("name").toString().compareTo(nam)==0) 112 { 113 isAccess = false; 114 break; 115 } 116 } 117 if(isAccess) 118 this.data.put(MetBuilder.getPointData(nam,str,50)); 119 } 120 } catch (SQLException e) { 121 e.printStackTrace(); 122 } 123 } 124 private void makeOneLink(String tableName,String linkSource){ 125 DBLink dbLink = new DBLink(new SqlUtils(new MySql_s("rc"),new UserInfo("root","123456"))); 126 try { 127 ReadableTable rt = dbLink.getSelect("Select word As word , SUM(num) As num From "+tableName+" Group By word Order By num DESC Limit 0,10"); 128 BeanGroup bg = rt.beans; 129 130 int leng_bg = bg.size(); 131 132 for(int i=0;i<leng_bg;++i) 133 { 134 JavaBean jbs = bg.get(i); 135 String nam = jbs.get(0).toString(); 136 137 this.link.put(MetBuilder.getLineData(linkSource,nam)); 138 } 139 } catch (SQLException e) { 140 e.printStackTrace(); 141 } 142 } 143 public static void main(String[] args) { 144 LockedModel lm = new LockedModel(); 145 System.out.println(lm.data.toString()); 146 System.out.println(); 147 System.out.println(lm.link.toString()); 148 System.out.println(); 149 System.out.println(LockedModel.dataSize); 150 System.out.println(); 151 System.out.println(LockedModel.linkSize); 152 } 153 }
2、Word报告生成
对于 Java 生成 Doc 文档部分,我早在之前做河北填报项目的时候做过了,想了解更多的话,自己去查找 POI 的相关知识,本篇博客不是来讲 POI 怎么用的,请博友勿问,自己去网上找相关的代码资料,我仅提供检索式:“Java POI 写 word ”
将 POI 相关 Jar 包 导入 lib 文件夹:
因为是去年10月多做项目来着,所以是那个时候的 Jar 包,也不知道更新没有。
为了防止因为MySql的原因,出现 SQLNonTransientConnectionException ,提前先设置好 最大连接数目:
//查看最大连接数目 show variables like 'max_connections'; //修改最大连接数目为1000 set GLOBAL max_connections=1000;
以上两句代码,需要以 Shell 模式运行 MySql 输入。
其次,需要我们整理构建顺序,我们写数据是一类一类写的,而我们可以在同步构建 Word 的目录结构和具体词频解释!(其中我写了链接跳转,但因为老师没有这方面的需求。于是我又把那部分代码注释掉了)
然后,我来分享我自己在项目制作过程中 POI 用到的知识点。
添加页码(参考博客:https://www.iteye.com/blog/53873039oycg-2149884)
添加标题(参考博客:https://blog.csdn.net/qq_28796037/article/details/99168627)
具体报告生成部分的代码不再给予(用到了多方博客的源码,免于侵权)
1 package com.servlet; 2 3 import java.io.IOException; 4 5 import javax.servlet.ServletException; 6 import javax.servlet.http.HttpServlet; 7 import javax.servlet.http.HttpServletRequest; 8 import javax.servlet.http.HttpServletResponse; 9 10 import com.docmake.FinalFunction; 11 12 13 public class ServletForMakeFiles extends HttpServlet{ 14 /** 15 * 16 */ 17 private static final long serialVersionUID = 1L; 18 19 //----------------------------------------------------------------------// 20 public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException 21 { 22 request.setCharacterEncoding("utf-8"); 23 response.setCharacterEncoding("utf-8"); 24 response.setContentType("application/json"); 25 response.setHeader("Cache-Control", "no-cache"); 26 27 String filepath = request.getParameter("filepath"); 28 29 FinalFunction ff = new FinalFunction(filepath); 30 31 ff.make(); 32 33 ff.close(); 34 } 35 //---------------------------------------------------------------------------------// 36 }
效果演示:
可以看到新添加了 “创建Doc文档” 按钮!
难得能在 10 天时间以内,做完这个项目啊!