ECharts异步获取数据

前端之家收集整理的这篇文章主要介绍了ECharts异步获取数据前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<Meta charset="utf-8">
<title>Insert title here</title>
<script type="text/javascript" src="static/js/jquery-3.1.1.min.js"></script>
<script type="text/javascript" src="static/js/echarts.js"></script>

</head>
<body>
 <div id="main" style="width: 1000px;height:400px;"></div><!-- 图标预留的空间 -->

<script> var myChart = echarts.init(document.getElementById('main')); // 指定图表的配置项和数据 $.get("json_test").done(function(obj){ var datas = JSON.parse(obj);//将json字符串转换成json对象 console.log(datas.series[1]); var datanam=[]; for(var i=0;i<datas.series.length;i++){ datanam.push(datas.series[i].name); } myChart.setOption({ title: { text: datas.title },tooltip: {},legend: { data:datanam },xAxis: { data: datas.xName },yAxis: {},series: datas.series }); }) </script>   
</body>
</html>

后台代码

@ResponseBody
    @RequestMapping("/json_test")
    public Object thisIsTest(){
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("C:/Users/Administrator/Desktop/test.json"),"utf-8"));

            try {

                StringBuilder sb = new StringBuilder();
                String data = null;
                while ((data = br.readLine())!=null) {
                    sb.append(data);
                }
                System.out.println(sb.toString());
                return sb.toString();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }



        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
原文链接:https://www.f2er.com/ajax/161074.html

猜你在找的Ajax相关文章