4
I’m implementing Graphics in a web application I’m developing in Spring. I already made my API, it is bringing Json with all the information of my object Cart, however the graphic is not being generated in the html page. Can anyone help me solve this problem? It does not present any error in the console.
html page, where the user chooses the month he wants to see the chart.
My service.
@RequestMapping(value = "/vendas", method = RequestMethod.GET)
public ResponseEntity<?> vendas(Long id, int valor) throws ParseException {
Usuario user = userService.findByEmail(SecurityContextHolder.getContext().getAuthentication().getName());
List<Carrinho> carrinhos = carrinhoService.findByRelatorioVenda(user.getId(), valor);
if (carrinhos.isEmpty()) {
return new ResponseEntity(new CustomErrorType("400"), HttpStatus.NOT_FOUND);
}
System.out.println(carrinhos);
return new ResponseEntity<List<Carrinho>>(carrinhos, HttpStatus.OK);
}
My html:
<section class="dashboard-header">
<div class="bar-chart-example card">
<div class="card-header d-flex align-items-center">
<h3 class="h4">Estatística anual</h3>
</div>
<div id="chartdiv1" class="chartdiv narrow float"></div>
</div>
</section>
<script type="text/javascript">
$(function() {
$("#btRelUm").click(function(e) {
e.preventDefault();
$.ajax({
method : "GET",
url : "/api/vendas",
data : {
valor : $("#mes").val()
}
}).done(function(data) {
/**
* TERCEIRO chart
*/
var chart = AmCharts.makeChart("chartdiv1", {
"theme" : "light",
"type" : "serial",
"startDuration" : 2,
"dataProvider" : data,
"valueAxes" : [ {
"position" : "left",
"title" : "Visitors"
} ],
"graphs" : [ {
"balloonText" : "[[category]]: <b>[[value]]</b>",
"fillColorsField" : "color",
"fillAlphas" : 1,
"lineAlpha" : 0.1,
"type" : "column",
"valueField" : "qtdovos"
} ],
"depth3D" : 20,
"angle" : 30,
"chartCursor" : {
"categoryBalloonEnabled" : false,
"cursorAlpha" : 0,
"zoomable" : false
},
"categoryField" : "bairro",
"categoryAxis" : {
"gridPosition" : "start",
"labelRotation" : 0
},
"titles" : [ {
"text" : "Quantidade de ovos por bairro"
} ],
"export" : {
"enabled" : true,
"menu" : []
}
});
}).fail(function(jqXHR, textStatus) {
});
});
});
</script>
What do you want to show in the chart? has various information being returned in the service, and you are putting everything on the chart
"dataProvider" : data
– N. Dias
want to pick up only the items dataEntrega and localEntrega
– Carlos Diego
I understand you want eggs per neighborhood right?
– N. Dias
How many graphics do you have on the same screen? It may be that you are associating multiples in the same variable. a simple way, would you take the result of your request (date/dataProvider) and paste it into some demo of the Amcharts itself and see if its structure is right. The operation of Amchart is very simple, and most of the time the problem is in the structure of the data, or some configuration of the chart that is using.
– Caio Koiti