<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="controller" />
<mvc:annotation-driven />
<bean
>
<property
value="org.springframework.web.servlet.view.JstlView" />
<property value="/WEB-INF/jsp/" />
<property value=".jsp" />
</bean>
<mvc:resources location="/WEB-INF/js/" mapping="/js/**"/>
<mvc:resources location="/WEB-INF/css/" mapping="/css/**"/>
</beans>
5.EchartsEntity.java
package po;
import java.util.List;
public class EchartsEntity {
public String name;
public String type;
public List<?> data;
public EchartsEntity() {
}
public EchartsEntity(String name, String type, List<?> data) {
super();
this.name = name;
this.type = type;
this.data = data;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public List<?> getData() {
return data;
}
public void setData(List<?> data) {
this.data = data;
}
}
6.EchartsServiceImpl.java
package service.impl;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Service;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import po.EchartsEntity;
import service.EchartsService;
@Service
public class EchartsServiceImpl implements EchartsService {
private ObjectMapper mapper = new ObjectMapper();
public String getLineImage() {
List<EchartsEntity> echarts = new ArrayList<EchartsEntity>();
//自定义横坐标
String[] xAxis = {"周一","周二","周三","周四","周五","周六","周日"};
//自定义三条线
EchartsEntity entity1 = new EchartsEntity("邮件营销","line",Arrays.asList(120, 132, 101, 134, 90, 230, 210));
EchartsEntity entity2 = new EchartsEntity("联盟广告","line",Arrays.asList(220, 182, 191, 234, 290, 330, 310));
EchartsEntity entity3 = new EchartsEntity("视频广告","line",Arrays.asList(150, 232, 201, 154, 190, 330, 410));
echarts.add(entity1);
echarts.add(entity2);
echarts.add(entity3);
String[] legend = {"邮件营销","联盟广告","视频广告"};
Map<String, Object> resultMap = new HashMap<String, Object>();
resultMap.put("xAxis", xAxis);
resultMap.put("series", echarts);
resultMap.put("legend", legend);
try {
return mapper.writeValueAsString(resultMap);
} catch (JsonProcessingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "";
}
}
7.EchartsTestController.java
package controller;