E aew Galera…
Estou com o seguinte problema, preciso gerar um grafico com base no resultado de uma consulta do BD.
mais nao sei como realizar a integracao entre o VRaptor e Google Charts
[code]@Resource
public class MainController {
private final Result result;
private final DaoFactory dao;
private final UsuarioWeb usuarioWeb;
private final Validator validator;
private final Session session;
public MainController(DaoFactory dao, Result result,
UsuarioWeb usuarioWeb, Validator validator, Session session) {
this.dao = dao;
this.result = result;
this.usuarioWeb = usuarioWeb;
this.validator = validator;
this.session = session;
}
@Path("/principal")
public void main() {
this.result.include("data", new Date());
this.result.use(Results.json()).withoutRoot().from(this.buscaDados()).serialize();
}
private List buscaDados(){
Criteria c = session.createCriteria(Visita.class, "v")
.createAlias("v.tipo", "tv", Criteria.INNER_JOIN)
.setProjection(Projections.projectionList()
// .add(Projections.groupProperty("tv.id"))
.add(Projections.groupProperty("tv.tipo"))
.add(Projections.count("tv.id")))
.add(Restrictions.eq("v.tecnico.codigo", new Long(414042)));
return c.list();
}[/code]
Trecho do codigo para geracao do grafico
Exemplo pagina do Google
Pagina JSP
<script type="text/javascript">
// 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(drawChart);
// Callback that creates and populates a data table,
// instantiates the pie chart, passes in the data and
// draws it.
function drawChart() {
// 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_div'));
chart.draw(data, options);
}
</script>
eu nao sei como pegar o meu json e setar no grafico