gpt4 book ai didi

javascript - 使用动态值的 jquery 图表示例

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

我想使用这个 jqchart bt,我不知道如何从我的 servlet 向这个函数传递值,而 servlet 又将从请求或 session 接收值。任何人都可以告诉我如何使这个函数具有动态值?提前致谢。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>HTML5 Chart jQuery Plugin - Multiple Axes </title>
<link rel="stylesheet" type="text/css" href="../css/jquery.jqChart.css" />
<script src="../js/jquery-1.5.1.min.js" type="text/javascript"></script>
<script src="../js/jquery.jqChart.min.js" type="text/javascript"></script>
<!--[if IE]><script lang="javascript" type="text/javascript" src="../js/excanvas.js"></script><![endif]-->
<script lang="javascript" type="text/javascript">
$(document).ready(function () {
$('#jqChart').jqChart({
title: { text: 'Multiple Axes' },
axes: [
{
name: 'y1',
location: 'left'
},
{
name: 'y2',
location: 'right',
strokeStyle: '#FCB441',
majorGridLines: { strokeStyle: '#FCB441' },
majorTickMarks: { strokeStyle: '#FCB441' }
}
],
series: [
{
type: 'column',
axisY: 'y1',
data: [['a', 1], ['b', 4], ['c', 3], ['d', 5], ['e', 2], ['f', 1]]
},
{
type: 'line',
axisY: 'y2',
data: [['a', 40], ['b', 60], ['c', 62], ['d', 52], ['e', 70], ['f', 75]]
}
]
});
});
</script>
</head>
<body>
<div>
<div id="jqChart" style="width: 500px; height: 300px;" />
</div>
</body>
</html>

最佳答案

您可以将 html 文件设为 jsp 页面或标签,然后动态呈现 javascript 函数。

在 servlet java 文件中准备数据,例如:

String myseriesData1 = "['a', 1], ['b', 4], ['c', 3], ['d', 5], ['e', 2], ['f', 1]";
String myseriesData2 = "['a', 40], ['b', 60], ['c', 62], ['d', 52], ['e', 70], ['f', 75]";

在 servlet 中渲染 jsp 并确保“数据”部分如下:

...
series: [
{type: 'column',axisY: 'y1',data: [${myseriesData1}]},
{type: 'line',axisY: 'y2',data: [${myseriesData2}]}]});

关于javascript - 使用动态值的 jquery 图表示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10269073/

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