如何使用ECharts和Java接口实现基于销售业绩的统计分析
如何使用ECharts和Java接口实现基于销售业绩的统计分析
@RestController @RequestMapping("/sales") public class SalesController { @GetMapping("/performance") public List getSalesPerformance() { // 从数据库或其他数据源获取销售业绩数据,并返回一个List对象 } }登录后复制
@GetMapping("/performance/chart") public String getSalesPerformanceChart() { List performanceList = getSalesPerformance(); // 构建ECharts所需的数据结构 JSONArray data = new JSONArray(); for (Performance performance : performanceList) { JSONObject item = new JSONObject(); item.put("name", performance.getName()); item.put("value", performance.getValue()); data.add(item); } JSONObject result = new JSONObject(); result.put("legend", new JSONArray()); result.put("data", data); return result.toJSONString(); }登录后复制
销售业绩统计分析 // 使用Ajax请求后端接口获取数据 var xhr = new XMLHttpRequest(); xhr.open('GET', '/sales/performance/chart', true); xhr.onreadystatechange = function () { if (xhr.readyState === 4 && xhr.status === 200) { var data = JSON.parse(xhr.responseText); // 使用ECharts库绘制图表 var chart = echarts.init(document.getElementById('chart')); var option = { series: [{ type: 'pie', name: '销售业绩', data: data.data }] }; chart.setOption(option); } }; xhr.send(); 登录后复制
注意:以上只是一个简单的示例代码,实际应用中可能需要根据具体需求进行调整和优化。
以上就是如何使用ECharts和Java接口实现基于销售业绩的统计分析的详细内容,更多请关注每日运维网(www.mryunwei.com)其它相关文章!