gpt4 book ai didi

javascript - 谷歌图表不显示在jsp中

转载 作者:行者123 更新时间:2023-12-02 13:28:13 25 4
gpt4 key购买 nike

我从 DAO 获取对象列表,并将其设置为 session 属性,以便在其他 jsps 中访问它,如下所示

list<PlayerBean> playerList=serviceDao.getPlayerData();
session.setAttribute("playerlist",playerList);

PlayerBean 有 2 个属性 1.playerName 2.runsscored

现在我正在尝试在 jsp 中显示玩家名与运行得分的条形图,并且我正在使用 google 图表 api,如下所示

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Graphical View</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">

google.charts.load('current', {packages: ['corechart', 'bar']});
google.charts.setOnLoadCallback(drawBasic);

function drawBasic()
{
var data = google.visualization.DataTable();
data.addColumn('string', 'Player Name');
data.addColumn('number', 'Runs Scored');

<c:forEach items="${playerlist}" var="listplayers">
data.addRow('${listplayers.playerName}',${listplayers.runsscored});
</c:forEach>

var options = {
title: 'Player Name vs Number of runs scored',
hAxis: {
title: 'Player Name'
},
vAxis: {
title: 'Runs Scored'
}
};

var chart = new google.visualization.ColumnChart(
document.getElementById('chart_div'));

chart.draw(data, options);
}}
</script>
</head>
<body>
<div id="chart_div"></div>
</body>
</html>

但是 jsp 中没有显示任何内容。

我尝试在 Chrome 中检查元素并查看页面源代码,如下所示

<html>
<head>
<title>Graphical View</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {packages: ['corechart', 'bar']});
google.charts.setOnLoadCallback(drawBasic);

function drawBasic() {
var data = google.visualization.DataTable();

data.addColumn('string', 'Player Name');
data.addColumn('number', 'Runs Scored');

data.addRow('John',250);
data.addRow('sachin',165);
data.addRow('ponting',54);
data.addRow('richards',320);

var options = {
title: 'Player Name vs Number of runs scored',
hAxis: {
title: 'Player Name'
},
vAxis: {
title: 'Runs Scored'
}
};

var chart = new google.visualization.ColumnChart(
document.getElementById('chart_div'));

chart.draw(data, options);
}
</script>
</head>
<body>
<div id="chart_div"></div>
</body>
</html>

这不是说浏览器正在获取数据但不显示吗?谁能帮我解决确切的问题可能是什么?并请提出一个解决方案。

提前致谢,

最佳答案

首先,在创建数据表时添加new关键字

var data = new google.visualization.DataTable()

添加括号,

addRow, it must be an array, or null

data.addRow(['${listplayers.playerName}',${listplayers.runss‌​cored}])

关于javascript - 谷歌图表不显示在jsp中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43304774/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com