Jump to content
JChartFX Community
  • 0

drilldown demo


jjlink
 Share

Question

 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

  • 0

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 

Link to comment
Share on other sites

  • 0

 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.

Link to comment
Share on other sites

  • 0

 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.

Link to comment
Share on other sites

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.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...