Skip to content Skip to sidebar Skip to footer

How Use Database In Javascript And JSF?

I'm trying to follow the @BalusC advice here. (I'm writing here now because it's unrelated with previous question). So I need to get data from my database and show in chart using J

Solution 1:

The JS expects a double[], but you're feeding a String[]. Fix it accordingly:

private double[] hestavollane = {
     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
};

private double[] voll = {
     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
};

public String getDataAsJson() {
    Map<String, Object> data = new HashMap<String, Object>();
    data.put("hestavollane", hestavollane);
    data.put("voll", voll);
    return new Gson().toJson(data);
}

And edit your spline-plot-bands.js file to use it instead of the hardcoded values:

series: [{
    name: 'Hestavollane',
    data: data.hestavollane
}, {
    name: 'Voll',
    data: data.voll
}]

Solution 2:

The key part of the linked article that you need is this:

<h:outputScript>var data = ${reportc.dataAsJson};</h:outputScript>

Post a Comment for "How Use Database In Javascript And JSF?"