I will need to pass a java variable to a javascript function. I have my codes as below. Wondering is that the correct way?
Because I have some problem here when the page first load, and the button is clicked, the chartData and categories is empty.
I am expecting the below:
chartData = [{"name":"Anne","data":[1.0,0.0,4.0]},
{"name":"Billy","data":[5.0,7.0,10000.0]}]
categories = ["APPLES","BANANAS","ORANGES"]
public String doLoadChartDataAction () {
String _cat = "[{\"name\":\"Anne\",\"data\":[1.0,0.0,4.0]},{\"name\":\"Billy\",\"data\":[5.0,7.0,10000.0]}]";
String _data = "[\"APPLES\",\"BANANAS\",\"ORANGES\"]";
System.out.println("1.0 " + " _cat:" + _cat);
System.out.println("1.0 " + " _data:" + _data);
setCategories(_cat);
setChartData(_data);
return "";
}
<p:commandButton styleClass="commandButton" value="This" id="btnThis" action="#{pc_Test.doLoadChartDataAction}"
oncomplete="renderChart('container','line','Sample Chart','${pc_Test.chartData}', '${pc_Test.categories}');">
</p:commandButton>