Page 1 of 2

graph a pie chart using variable names (jqplot)

Posted: Mon Dec 16, 2013 6:37 pm
by Alex GG

hello Appery team,
I ́m using this example to graph a pie using jqplot:
(if I use numbers for aa, bb, cc the graph is draw. but if I use the variables names, it fails.
I have take a look into stackoverflow questions, and also here in the question about ride trip, but I couldn ́t get it work.

____________

var aa = localStorage.getItem("aa");
var bb = localStorage.getItem("bb");
var cc = localStorage.getItem("cc");
$(document).ready(function(){
var data = [
['sales', aa],['service', bb], ['maintenance', cc]
];
var plot1 = jQuery.jqplot ('chart1', [data],
{
seriesDefaults: {
// Make this a pie chart.
renderer: jQuery.jqplot.PieRenderer,
rendererOptions: {
// Put data labels on the pie slices.
// By default, labels show the percentage of the slice.
showDataLabels: true
}
},
legend: { show:true, location: 'e' }
}
);
});

_________

the problem is that I get the aa,bb,cc, and d values from REST.
No errors in console.

could you help me with this? Thanks


graph a pie chart using variable names (jqplot)

Posted: Mon Dec 16, 2013 6:44 pm
by maxkatz

A couple of things you should try:

  • Check to make sure you are getting the right values for aa, bb, cc.
  • Test this to make sure it works in a plain HTML page (outside of Appery.io)

graph a pie chart using variable names (jqplot)

Posted: Mon Dec 16, 2013 6:51 pm
by Alex GG

I use labels, and alert(), and I get the right value from rest, when testing.

________

in this question on other post (Journey Recording using GPS Tracking )
they are able to use variables in the array...

___________

points.push([(coordsArray.time - startTime) / 1000 / 60, avrSpeed/j]);
avrSpeed = 0;
j = 0;
}
}
var plot1 = $.jqplot('plot1', [points], {

______

graph a pie chart using variable names (jqplot)

Posted: Mon Dec 16, 2013 7:23 pm
by Kateryna Grynko

Hi Alex,

Please try this on an empty page with static data.


graph a pie chart using variable names (jqplot)

Posted: Mon Dec 16, 2013 7:29 pm
by Alex GG

hello KAtya, I have already tried with static data, and works OK.
but when change to variable names it fails. Image


graph a pie chart using variable names (jqplot)

Posted: Mon Dec 16, 2013 9:17 pm
by Kateryna Grynko

Alex,

Please try the following to get variables:prevar aa = parseInt(localStorage.getItem("aa"));
var bb = parseInt(localStorage.getItem("bb"));
var cc = parseInt(localStorage.getItem("cc"));/pre


graph a pie chart using variable names (jqplot)

Posted: Mon Dec 16, 2013 9:39 pm
by Alex GG

wonderful! I works now. Thanks


graph a pie chart using variable names (jqplot)

Posted: Mon Dec 16, 2013 9:47 pm
by Kateryna Grynko

Alex,

Glad it's working!


graph a pie chart using variable names (jqplot)

Posted: Tue Dec 17, 2013 9:25 pm
by Alex GG

Hello KAtya, I have another question. I ́ve been strugling to add the values return on REST service.
This APP is to graph the income of a bussiness per week or month. So when the user sells something he enters the price, and click save. I ́ve a service to crate and update the DB. So, at any time, when the user wants to see the graph, he click "show results" and I call service with "where" to pick different categories (as in the last question aa, bb, cc).
I have look at other post like this https://getsatisfaction.com/apperyio/..., but could no get it works..
this is my db: Image
one service uses : return '{"servicio":"bb"}'; and if I map on a label I get the two values(600 and 400),, so what I need to do to add those, and get the result (1000), to pass to the pie chart?? In the above example there are only two values, but could be much more. So I was thinking to create and array, and push the values, then use "for" to sum all values.

could you give a hint,,,thankss!!!!


graph a pie chart using variable names (jqplot)

Posted: Tue Dec 17, 2013 10:40 pm
by Igor

Hello,

You can save array to localStorage variable https://getsatisfaction.com/apperyio/... and calculate the sum of values in an array http://stackoverflow.com/questions/16...