How can I make a piechart with data coming from a web service ?.
The data that the web service shows comes in json format; this is an example of the output of my web service, which is called ws_lugares.php
:
{
"procede": "1",
"status": "1",
"statusText": "Correct",
"Lugares": [
{
"México": "3",
"Ecuador": "2",
"Tijuana": "5"
}
]
}
***** E STATE USING this code the url: that is where my web service is located ******
<script>
$.ajax({
url: '../ws_lugares.php',
type: 'POST',
dataType: 'json',
data: $(this).serialize()
})
.done(function (respuesta) {
console.log(respuesta);
if (!respuesta.error) { //Aqui se les da el valor de el ws a variables para despues llamarlas en el value de la grafica
} else {
$('.error').slideDown('slow');
setTimeout(function () {
$('.error').slideUp('slow');
}, 3500);
}
})
.fail(function (resp) {
console.log(resp.responseText);
})
.always(function () {
console.log("complete");
});
var pieChartCanvas = $('#pieChart').get(0).getContext('2d')
var pieChart = new Chart(pieChartCanvas)
var PieData = [
{
value : //Aqui se llama la 1er var,
color : '#f56954',
highlight: '#f56954',
label : 'Chrome'
},
{
value : //aqui se llama la 2da ,
color : '#00a65a',
highlight: '#00a65a',
label : 'IE'
},
{
value : /aqui se llama la tercer,
color : '#f39c12',
highlight: '#f39c12',
label : 'FireFox'
}
]
var pieOptions = {
//Boolean - Whether we should show a stroke on each segment
segmentShowStroke : true,
//String - The colour of each segment stroke
segmentStrokeColor : '#fff',
//Number - The width of each segment stroke
segmentStrokeWidth : 2,
//Number - The percentage of the chart that we cut out of the middle
percentageInnerCutout: 50, // This is 0 for Pie charts
//Number - Amount of animation steps
animationSteps : 100,
//String - Animation easing effect
animationEasing : 'easeOutBounce',
//Boolean - Whether we animate the rotation of the Doughnut
animateRotate : true,
//Boolean - Whether we animate scaling the Doughnut from the centre
animateScale : false,
//Boolean - whether to make the chart responsive to window resizing
responsive : true,
// Boolean - whether to maintain the starting aspect ratio or not when responsive, if set to false, will take up entire container
maintainAspectRatio : true,
//String - A legend template
legendTemplate : '<ul class="<%=name.toLowerCase()%>-legend"><% for (var i=0; i<segments.length; i++){%><li><span style="background-color:<%=segments[i].fillColor%>"></span><%if(segments[i].label){%><%=segments[i].label%><%}%></li><%}%></ul>'
}
</script>
*** this is what I tried to clear that I have the #piechart but do not place it here because the problem I have is that I do not know how to accommodate the values of the ws to translate them into the graphic ****