gpt4 book ai didi

java - 使用 google API 在 jsp 页面上显示流程图的最佳方式

转载 作者:行者123 更新时间:2023-12-01 05:15:53 25 4
gpt4 key购买 nike

我对 Google API 流程图有疑问。我想在一个 jsp 页面上添加几个流程图。在我的流程图 Controller 中,我运行从数据库获得的列表,并且我想为 foreach 制作一个流程图。

将其添加到模型并将其显示在 jsp 页面上的最佳方法是什么?

流程图代码是这样的:

    <script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Year', 'Sales', 'Expenses'],
['2004', 1000, 400],
['2005', 1170, 460],
['2006', 660, 1120],
['2007', 1030, 540]
]);

var options = {
title: 'Company Performance'
};

var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>

该代码但在 for 循环中填充了我的值,但我不知道如何将其提供给模型? (由于 String 不起作用,我只是尝试过:D)

最佳答案

在一页中显示 2 个图表的代码。您可以调整逻辑并达到您的要求。 Docs

      // Load the Visualization API and the piechart package.
google.load('visualization', '1.0', {'packages':['corechart']});

// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart1);
google.setOnLoadCallback(drawChart2);

// Callback that creates and populates a data table,
// instantiates the pie chart, passes in the data and
// draws it.
function drawChart1() {

// Create the data table.
var data = new google.visualization.DataTable();
data.addColumn('string', 'Topping');
data.addColumn('number', 'Slices');
data.addRows([
['Mushrooms', 3],
['Onions', 1],
['Olives', 1],
['Zucchini', 1],
['Pepperoni', 2]
]);

// Set chart options
var options = {'title':'How Much Pizza I Ate Last Night',
'width':400,
'height':300};

// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.PieChart(document.getElementById('chart_div1'));
chart.draw(data, options);
}
function drawChart2() {

// Create the data table.
var data = new google.visualization.DataTable();
data.addColumn('string', 'Topping');
data.addColumn('number', 'Slices');
data.addRows([
['Mushrooms', 3],
['Onions', 1],
['Olives', 1],
['Zucchini', 1],
['Pepperoni', 2]
]);

// Set chart options
var options = {'title':'How Much Pizza I Ate Last Night',
'width':400,
'height':300};

// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.BarChart(document.getElementById('chart_div2'));
chart.draw(data, options);
}

</script>
</head>

<body>
<!--Div that will hold the pie chart-->
<div id="chart_div1"></div>
<div id="chart_div2"></div>
</body>
</html>

关于java - 使用 google API 在 jsp 页面上显示流程图的最佳方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11222897/

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