I am currently following the recommendations provided by @BalusC, with additional guidance available here. (The reason I'm posting this here is because it's not related to my previous question).
My goal is to retrieve data from my database and display it in a chart using JavaScript; an example of this can be seen here. I am working on this prototype to gain an understanding of how to transfer data from the server side to the client side.
This is a snippet of my bean:
@ManagedBean(name="reportc")
@ViewScoped
public class ReportControl implements Serializable {
private static final long serialVersionUID = 3269125738504434502L;
private String[] dataAsJson = {"1.3", "2.1", "1.3", "2.2", "1.4", "2.7", "1.5", "2.1", "1.6", "2.4", "1.9", "2.1"};
public String getDataAsJson() {
Gson gson = new Gson();
return gson.toJson(dataAsJson);
}
}
A useful resource for understanding the spline-plot-bands.js file.
<!DOCTYPE html>
<html lang="en"
xmlns="http://www.w3.org/1999/xhtml"
...
<h:head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<h:outputScript>var data = ${reportc.dataAsJson};</h:outputScript>
<h:outputScript name="javascript/highchart/spline-plot-bands.js" />
</h:head>
<h:body>
<h:outputScript name="javascript/highchart/highcharts.js" />
<h:outputScript name="javascript/highchart/modules/exporting.js" />
<div id="container" style="width: 800px; height: 400px; margin: 0 auto"></div>
</h:body>
</html>
In the spline-plot-bands.js file, pay attention to this section:
series: [{
name: 'Hestavollane',
data: [4.3, 5.1, 4.3, 5.2, 5.4, 4.7, 3.5, 4.1, 5.6, 7.4, 6.9, 7.1,
7.9, 7.9, 7.5, 6.7, 7.7, 7.7, 7.4, 7.0, 7.1, 5.8, 5.9, 7.4,
8.2, 8.5, 9.4, 8.1, 10.9, 10.4, 10.9, 12.4, 12.1, 9.5, 7.5,
7.1, 7.5, 8.1, 6.8, 3.4, 2.1, 1.9, 2.8, 2.9, 1.3, 4.4, 4.2,
3.0, 3.0]
}, {
name: 'Voll',
data: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.1, 0.0, 0.3, 0.0,
0.0, 0.4, 0.0, 0.1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.6, 1.2, 1.7, 0.7, 2.9, 4.1, 2.6, 3.7, 3.9, 1.7, 2.3,
3.0, 3.3, 4.8, 5.0, 4.8, 5.0, 3.2, 2.0, 0.9, 0.4, 0.3, 0.5, 0.4]
}]
I am seeking advice on how to transmit similar data from the server side to this JavaScript. Although I have made progress in utilizing Gson, JavaScript with JSF, there are still some aspects that elude me. Any assistance would be greatly appreciated.