1

I am using the code at http://jsfiddle.net/MX7JC/9/ to build a pie chart.

But I want the data to come from php variables. How do I change :

var agg = { label: 'Aggressive', pct: [60, 10, 6, 30, 14, 10] },

as seen in the code on the link, so that pct consists of an array of php variables rather than fixed numbers. Such as :

var agg = { label: 'Aggressive', pct: [$r1, $r2, $r3, $r4, $r5, $r6]},

How do I alter the code to allows this? I tried json encode and I am having problems.

1 Answer 1

1

You can generate the Javascript when it's defined using PHP:

<script type="text/javascript">
    var agg = { label: 'Aggressive', pct: [
        <?php echo $r1.", ".$r2.", ".$r3.", ".$r4.", ".$r5.", ".$r6; ?>
    ]},
</script>
Sign up to request clarification or add additional context in comments.

2 Comments

When I used this, and other similar methods, and applied it to the code from the jsfiddle link in my question, the entire visualization does not render in the browser anymore, it goes away.
Never mind. I figured it out. It was another simply issue to address. Thanks anyway.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.