https://download.csdn.net/download/qq_31293575/14884249
一、HighCharts简介
Highcharts 是一个用纯JS编写的一个图表库,能够很简单便捷的在web网站或是web应用程序添加有交互性的图表,并且免费提供给个人学习、个人网站和非商业用途使用。HighCharts支持的图表类型有曲线图、区域图、柱状图、饼状图、散状点图和综合图表。
二、入门案例
第一步:将Highcharts相关资源文件复制到项目中
第二步:在页面中引入相关js文件
-
<script type="text/javascript" src="${pageContext.request.contextPath }/js/jquery-1.8.3.js"></script>
-
<script src="${pageContext.request.contextPath }/js/highcharts/highcharts.js"></script>
-
<script src="${pageContext.request.contextPath }/js/highcharts/modules/exporting.js"></script>
第三步:在页面中提供一个div,并指定id属性
-
<body>
-
<div id="test"></div>
-
</body>
第四步:调用Highcharts提供的方法,动态创建图表
-
$(function(){
-
//页面加载完成后,动态创建图表
-
$("#test").highcharts({
-
title: {
-
text: '各浏览器份额'
-
},
-
series: [{
-
type: 'pie',
-
name: '浏览器占比',
-
data: [
-
['Firefox', 45.0],
-
['IE', 26.8],
-
['Safari', 8.5],
-
['Opera', 6.2],
-
['Others', 0.7]
-
]
-
}]
-
});
-
});
效果展示
package com.liquid.excel.excel;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
@Controller
public class IndexController {
@RequestMapping("/")
public String getIndex(){
return "/index";
}
@RequestMapping("/getData")
@ResponseBody
public List<Object> getData(@RequestParam("rowNum")Integer rowNum) throws Exception{
List<Object> bankListByExcel = ExcelFormatUtil.getBankListByExcel(rowNum);
return bankListByExcel;
}
}
package com.liquid.excel.excel;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.util.ArrayList;
import java.util.List;
public class ExcelFormatUtil {
/**
* 读取excel表
*
* @param
* @param
* @return Workbook work = new XSSFWorkbook("D://GoolgeDownload//Summary.xlsx");
* @throws Exception
*/
public static List<Object> getBankListByExcel(int rowNum) throws Exception {
List<Object> list = new ArrayList<>(); // 读取的数据放入该集合中
XSSFWorkbook book = new XSSFWorkbook("D:\\dredging_data_a.xlsx"); // 文件所在位置
XSSFSheet sheet = book.getSheetAt(0);
XSSFRow row = sheet.getRow(rowNum);
if (row != null) {
double name = row.getCell(0).getNumericCellValue();
list.add(name);
double b = row.getCell(1).getNumericCellValue(); // 医院名称 // 这边为读取的字段名称 ,写自己的就好
list.add(b); // 将读取的数据放入集合
double c = row.getCell(2).getNumericCellValue(); // 医院名称 // 这边为读取的字段名称 ,写自己的就好
list.add(c); // 将读取的数据放入集合
double d = row.getCell(3).getNumericCellValue(); // 医院名称 // 这边为读取的字段名称 ,写自己的就好
list.add(d); // 将读取的数据放入集合
String e = row.getCell(4).getStringCellValue(); // 医院名称 // 这边为读取的字段名称 ,写自己的就好
list.add(e); // 将读取的数据放入集合
}
return list;
}
}