从MySQL拉出时不会显示Canvas JS图表

时间:2020-02-18 10:12:15

标签: jsp canvasjs

任何人都可以看到以下原因不显示甜甜圈图的原因吗?根据我关闭的时间,它会显示图表,但仅显示数据库中的最后一个条目,而它会打印其他两个条目,并以{ label: "Ireland", y: 2 }的形式显示在文本中。我认为如果现在在适当的位置关闭了一段时间,但什么也没有显示。 (我知道我应该使用准备好的陈述-缺乏经验的道歉)

 <%

                            Statement stat = null;
                            ResultSet res = null;
                            stat = conn.createStatement();
                            String data = "SELECT COUNT(user_id) AS count_user, user_country FROM user GROUP BY user_country;";

                            res = stat.executeQuery(data);

                            while(res.next()){
                        %>


                        <tr>
                            <td><%= res.getInt("count_user")%></td>
                            <td><%= res.getString("user_country")%></td>
                           </tr>
                        <%
                            }
                         %>
                    </tbody>
                </table>
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
<script type="text/javascript">

window.onload = function () {
    var chart = new CanvasJS.Chart("chartContainer", {
        title:{
            text: "Alumni by country"              
                        },

        data: 
                      [

                        {
                            // Change type to "doughnut", "line", "splineArea", etc.
                                type: "doughnut",

                                dataPoints:             

                                <%  res = stat.executeQuery(data);

                                 while(res.next()){
                                %> 

                                [  

                { label: "<%= res.getString("user_country")%>",  y: <%= res.getString("count_user")%> }

                                ]

                                                <%}%>
                        }
        ]
    });
    chart.render();
};
}
</script>
<body>
<div id="chartContainer" style="height: 300px; width: 100%;"></div>
</body>

1 个答案:

答案 0 :(得分:0)

似乎每个{label ...}块后面都缺少逗号(当然,最后一个除外)