loubobooo 2017-05-24 07:49 采纳率: 66.7%
浏览 4694
已结题

echart图表不显示的问题

    <script type="text/javascript">
// 路径配置
require.config({
    paths : {
        echarts : 'http://echarts.baidu.com/build/dist'
    }
});
// 使用
require([ 'echarts', 'echarts/chart/bar' // 使用柱状图就加载bar模块,按需加载
], 
drewEcharts

);
function drewEcharts(ec) {
// 基于准备好的dom,初始化echarts图表
var myChart = ec.init(document.getElementById('main'));

    var option = {
        tooltip : {
            show : true
        },
        legend : {
            data : [ '人数' ]
        },
        xAxis : [ {
            type : 'category',
            data :(function(){
                                var arr=[];
                                    $.ajax({
                                    type : "post",
                                    async : false, //同步执行
                                    url : "bar.do",
                                    data : {},
                                    dataType : "json", //返回数据形式为json
                                    success : function(result) {
                                    if (result) {
                                        /* alter("first"); */
                                           for(var i=0;i<result.length;i++){
                                              console.log(result[i].name);
                                              arr.push(result[i].name);
                                            }    
                                    }

                                },
                                error : function(errorMsg) {
                                    alert("不好意思,图表请求数据失败啦!");
                                    myChart.hideLoading();
                                }
                               })
                               return arr;
                            })() 

        } ],
        yAxis : [ {
            type : 'value'
        } ],
        series : [ {
            "name" : "人数",
            "type" : "bar",
            "data" : (function(){
                                    var arr=[];
                                    $.ajax({
                                    type : "post",
                                    async : false, //同步执行
                                    url : "bar.do",
                                    data : {},
                                    dataType : "json", //返回数据形式为json
                                    success : function(result) {
                                    if (result) {
                                           for(var i=0;i<result.length;i++){
                                              console.log(result[i].num);
                                              arr.push(result[i].num);
                                            }  
                                    }
                                },
                                error : function(errorMsg) {
                                    alert("不好意思,大爷,图表请求数据失败啦!");
                                    myChart.hideLoading();
                                }
                               })
                              return arr;
                        })()

        } ]
    };
    // 为echarts对象加载数据 
    myChart.setOption(option);
}

图片说明

  • 写回答

3条回答 默认 最新

  • loubobooo 2017-05-24 07:56
    关注

    Connection connection;

    public Connection getConnection() {
        try {
            String name = "admin";
            String password = "123456";
            String url = "jdbc:mysql://localhost:3306/todo_ssm";
            Class.forName("com.mysql.jdbc.Driver");
            connection = DriverManager.getConnection(url, name, password);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return connection;
    }
    
    public void setConnection(Connection connection) {
        this.connection = connection;
    }
    
    public List<barBean> listAll() {
        ArrayList<barBean> list = new ArrayList<barBean>();
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        try {
            pstmt = this.getConnection().prepareStatement("SELECT * FROM records");
            rs = pstmt.executeQuery();
            while (rs.next()) {
                barBean bar = new barBean();
                bar.setName(rs.getString("name"));
                bar.setSum(rs.getInt("sum"));
                list.add(bar);
                System.out.println("连接数据库成功");
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                connection.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return list;
    }
    
    java代码如下,数据是获取到了,就是不显示图表![图片说明](https://img-ask.csdn.net/upload/201705/24/1495612569_329148.png)
    
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?