import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import service.EchartsService;
@RestController
@RequestMapping(value="/echarts",produces=MediaType.TEXT_HTML_VALUE+";charset=utf-8")
public class EchartsTestController {
@Autowired
public EchartsService echartsService;
@RequestMapping("/showImage")
public String showImage() {
String value = echartsService.getLineImage();
System.out.println(value);
return value;
}
}
8.ShowPageController.java
package controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class ShowPageController {
@RequestMapping("/{page}")
public String showPage(@PathVariable String page) {
return page;
}
}
9.前台jsp页面
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="https://www.linuxidc.com/js/jquery-2.1.4/jquery.min.js"></script>
<script type="text/javascript" src="https://www.linuxidc.com/js/ehcarts/echarts-all.js"></script>
<!--
<script type="text/javascript" src="https://www.linuxidc.com/js/echarts-2.2.7/build/dist/echarts-all.js"></script>
-->
<title>Insert title here</title>
</head>
<body>
<div></div>
<script type="text/javascript">
var myChart = echarts.init(document.getElementById('line'));
var lineOption = {
title : {
text: '',
subtext: ''
},
tooltip : {
trigger: 'axis' //item 点在哪条线上显示哪条线上的数据,axis点在哪个坐标点上显示对于点上所有数据
},
legend: {
data:[]
},
toolbox: {
show : true,
orient : 'vertical',
x: 'right',
y: 'center',
feature : {
mark : {show: true},
dataView : {show: true, readOnly: false},
magicType : {show: true, type: ['line', 'bar']},
restore : {show: true},
saveAsImage : {show: true}
}
},
calculable : true,
xAxis : [
{
type : 'category',
boundaryGap : false,
data : []
}
],
yAxis : [
{
type : 'value',
axisLabel : {
formatter: '{value} '
}
}
],
series : []
};