jsf - Google chart: How to pass the datatable from Java files to JavaScript -


hello try using google chart display trendlines, based on datas generated java files. here part of codes

public void resolveevolution() {         this.evolution = new arraylist<long>();         this.evolutiontime = new arraylist<string>();         calendar first = calendar.getinstance();         first.settime(this.start);         first.set(calendar.day_of_month, 1);         calendar last = calendar.getinstance();         last.settime(this.end);          int = 0;          this.dt = datatable.create();         dt.addcolumn(columntype.number, "time");         dt.addcolumn(columntype.number, "utilisation");         dt.addrow();         while (first.before(last)) {             calendar endmonth = calendar.getinstance();             endmonth.settime(first.gettime());             endmonth.add(calendar.month, 1);             endmonth.add(calendar.day_of_month, -1);              this.evolution                     .add(actionqueries.countbycomponent(this.selectedcomponent,                             first.gettime(), endmonth.gettime()));             this.evolutiontime.add(first.get(calendar.month) + "/"                     + first.get(calendar.year));             dt.addrow();             dt.setvalue(i, 0, i);             dt.setvalue(i, 1,                     actionqueries.countbycomponent(this.selectedcomponent,                             first.gettime(), endmonth.gettime()));             i++;             first.add(calendar.month, 1);         }     }      public datatable getdt() {         system.out.println(this.dt);         return this.dt;     } 

here xhtml:

<?xml version="1.0" encoding="utf-8"?> <!doctype html public "-//w3c//dtd xhtml 1.0 strict//en" "dtd/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"     xmlns:h="http://java.sun.com/jsf/html"     xmlns:f="http://java.sun.com/jsf/core">     <head>     <script type="text/javascript" src="https://www.google.com/jsapi"></script>     <script type="text/javascript">           google.load("visualization", "1", {packages:["corechart"]});          google.setonloadcallback(drawchart);           function drawchart() {                 var data = new google.visualization.datatable();         data = "#{globalcomponentsmanager.dt}";         var options = {                      title: 'test',                            trendlines: { 0: {} }          };             var chart = new google.visualization.scatterchart(document.getelementbyid('chart_div'));          chart.draw(data, options);           }         </script>   </head>    <body>          <div id="chart_div" style="width: 900px; height: 500px;"></div>   </body>   </html> 

obviously, doesn't work. how can pass datatable java javascript ? using jsf frame. thanks.

well, found solution @ last. , hope people meet same difficulty in future. jsf pass parameters java web page, including javascript within jsf page. use stringbuilder in java file building string of rows, [[1,2],[5,9],[4,3]]. , pass string javascript, codes of google chart, data.addrows(#{stastics.rows}). other parts of google chart codes, refer google chart documentations. worked , got chart needed finally.


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -