jjlink Posted December 17, 2013 Report Share Posted December 17, 2013 can I pass a variable into the array. I am running php against a db to get the values. wondering if I can pass that into a value in the array? function doData() { chart1.getDataSourceSettings().getFields().clear(); var items = [{ /*"Country": "Costa Rica", "Value": 3711095 }, { "Country": "El Salvador", "Value": 6125782 }, { "Country": "Guatemala", "Value": 11085025 }, { "Country": "Honduras", "Value": 6347658 }, { "Country": "Nicaragua", "Value": 4935148*/ "Country": "Array Overhead", "Value": 3711095 }, { "Country": "Usable", "Value": 10000 }]; chart1.setDataSource(items); } Quote Link to comment Share on other sites More sharing options...
0 JuanC Posted December 30, 2013 Report Share Posted December 30, 2013 I am not entirely sure what you mean by "can I pass a variable into the array". If you are generating the json on the server, your php would connect to the db and generate the json using the values from the db. If you get the json from the server and want to tweak the data you can always modify the items objects before passing them to the chart, e.g. var first = items[0]; first["Value"] = aNumberVariable; Or you can create a new object and add it to the array, e.g. var elem = {}; elem["Country"] = "Venezuela"; elem["Value"] = 4000; items.push(elem) Regards, JuanC Quote Link to comment Share on other sites More sharing options...
0 jjlink Posted January 2, 2014 Author Report Share Posted January 2, 2014 Juan, I can tweak the data i.e. var first = items[0]; first["Value"] = aNumberVariable; but when I do the whole pie does not show up,just a sliver. function doData() { var varUsable = "<?php echo $Usable; ?>"; var varOverhead = "<?php echo $Overhead; ?>"; chart1.getDataSourceSettings().getFields().clear(); var items = [{ /*"Country": "Costa Rica", "Value": 3711095 }, { "Country": "El Salvador", "Value": 6125782 }, { "Country": "Guatemala", "Value": 11085025 }, { "Country": "Honduras", "Value": 6347658 }, { "Country": "Nicaragua", "Value": 4935148*/ "Country": "Array Overhead", "Value": 3711095 }, { "Country": "Usable", "Value": 100 }]; var second = items[1]; second["Value"] = varOverhead; chart1.setDataSource(items); } thanks so much for the help, this is really cool. Quote Link to comment Share on other sites More sharing options...
0 JuanC Posted January 3, 2014 Report Share Posted January 3, 2014 Can you post the client script that gets to the client, i.e. we would need to see what varOverhead is at the client. Is it possible the first number in the array is so big (3711095) than when compared with the other one is almost 100% of the total? Regards, JuanC Quote Link to comment Share on other sites More sharing options...
0 jjlink Posted January 6, 2014 Author Report Share Posted January 6, 2014 Juan, the issue appears to be the following: when you hard code the values it adds them up to create the whole pie, then divides each piece. when you use a variable it concatenates the values to come up with the size of the pie. function doData() { var varUsable = "<?php echo $Usable; ?>"; var varOverhead = "<?php echo $Overhead; ?>"; chart1.getDataSourceSettings().getFields().clear(); var items = [{ /*"Country": "Costa Rica", "Value": 3711095 }, { "Country": "El Salvador", "Value": 6125782 }, { "Country": "Guatemala", "Value": 11085025 }, { "Country": "Honduras", "Value": 6347658 }, { "Country": "Nicaragua", "Value": 4935148*/ "Country": "Array Overhead", "Value": 30 }, { "Country": "Usable", "Value": varUsable }]; /*var second = items[1]; second["Value"] = varOverhead;*/ chart1.setDataSource(items); } the value of varUsable is 58. the pie them becomes 3058. if I hard code the value to be 58, the pie becomes 88. Quote Link to comment Share on other sites More sharing options...
0 jjlink Posted January 6, 2014 Author Report Share Posted January 6, 2014 I got it. I was passing the variable as a string and not a integer. As you can see I am very shaky with javascript. I have the pie working and will now concentrate on the drilldown. Thanks much for your patience and help. Quote Link to comment Share on other sites More sharing options...
Question
jjlink
can I pass a variable into the array. I am running php against a db to get the values. wondering if I can pass that into a value in the array?
function doData() {
chart1.getDataSourceSettings().getFields().clear();
var items = [{
/*"Country": "Costa Rica",
"Value": 3711095
}, {
"Country": "El Salvador",
"Value": 6125782
}, {
"Country": "Guatemala",
"Value": 11085025
}, {
"Country": "Honduras",
"Value": 6347658
}, {
"Country": "Nicaragua",
"Value": 4935148*/
"Country": "Array Overhead",
"Value": 3711095
}, {
"Country": "Usable",
"Value": 10000
}];
chart1.setDataSource(items);
}
Link to comment
Share on other sites
5 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.